Skip to content

Commit

Permalink
Small fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanSweet committed Nov 5, 2017
1 parent cb0f340 commit 93b859a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.esotericsoftware</groupId>
<artifactId>jsonbeans</artifactId>
<version>0.8-SNAPSHOT</version>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>JsonBeans</name>
<description>Java object graphs, to and from JSON automatically</description>
Expand Down
4 changes: 3 additions & 1 deletion src/com/esotericsoftware/jsonbeans/Json.java
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ public void readFields (Object object, JsonValue jsonMap) {
Class type = object.getClass();
ObjectMap<String, FieldMetadata> fields = getFields(type);
for (JsonValue child = jsonMap.child; child != null; child = child.next) {
FieldMetadata metadata = fields.get(child.name());
FieldMetadata metadata = fields.get(child.name().replace(" ", "_"));
if (metadata == null) {
if (ignoreUnknownFields) {
if (debug) System.out.println("Ignoring unknown field: " + child.name() + " (" + type.getName() + ")");
Expand Down Expand Up @@ -864,6 +864,8 @@ public <T> T readValue (Class<T> type, Class elementType, JsonValue jsonData) {
if (typeName != null && Collection.class.isAssignableFrom(type)) {
// JSON object wrapper to specify type.
jsonData = jsonData.get("items");
if (jsonData == null)
throw new JsonException("Unable to convert object to collection: " + jsonData + " (" + type.getName() + ")");
} else {
JsonSerializer serializer = classToSerializer.get(type);
if (serializer != null) return (T)serializer.read(this, jsonData, type);
Expand Down
5 changes: 3 additions & 2 deletions src/com/esotericsoftware/jsonbeans/JsonValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* for (JsonValue entry = map.child; entry != null; entry = entry.next)
* System.out.println(entry.name + " = " + entry.asString());
* </pre>
*
* @author Nathan Sweet */
public class JsonValue implements Iterable<JsonValue> {
private ValueType type;
Expand Down Expand Up @@ -65,7 +66,7 @@ public JsonValue get (int index) {
* @return May be null. */
public JsonValue get (String name) {
JsonValue current = child;
while (current != null && !current.name.equalsIgnoreCase(name))
while (current != null && (current.name == null || !current.name.equalsIgnoreCase(name)))
current = current.next;
return current;
}
Expand All @@ -92,7 +93,7 @@ public JsonValue require (int index) {
* @throws IllegalArgumentException if the child was not found. */
public JsonValue require (String name) {
JsonValue current = child;
while (current != null && !current.name.equalsIgnoreCase(name))
while (current != null && (current.name == null || !current.name.equalsIgnoreCase(name)))
current = current.next;
if (current == null) throw new IllegalArgumentException("Child not found with name: " + name);
return current;
Expand Down

0 comments on commit 93b859a

Please sign in to comment.