Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,26 @@ public static Object toObject(JsonNode jsonNode) {
}

public static Object toObject(JsonNode jsonNode, Schema schema) {
if (schema != null && schema.getType().equals(Schema.Type.UNION)) {
return toObject(jsonNode, schema.getTypes().get(0));
}
if (jsonNode == null) {
return null;
} else if (jsonNode.isNull()) {
return JsonProperties.NULL_VALUE;
} else if (jsonNode.isBoolean()) {
}

if (schema != null && schema.getType().equals(Schema.Type.UNION)) {
for (Schema unionType : schema.getTypes()) {
if (unionType.getType().equals(Schema.Type.NULL)) {
continue;
}
Object unionObject = toObject(jsonNode, unionType);
if (unionObject != null) {
return unionObject;
}
}
return null;
}

if (jsonNode.isBoolean()) {
return jsonNode.asBoolean();
} else if (jsonNode.isInt()) {
if (schema == null || schema.getType().equals(Schema.Type.INT)) {
Expand Down Expand Up @@ -187,7 +199,7 @@ public static Object toObject(JsonNode jsonNode, Schema schema) {

/**
* Convert an object into a map
*
*
* @param datum The object
* @return Its Map representation
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ void testToObject() {
toObject(NullNode.getInstance(), SchemaBuilder.unionOf().nullType().and().intType().endUnion()));

assertEquals("a", toObject(TextNode.valueOf("a"), SchemaBuilder.unionOf().stringType().and().intType().endUnion()));

assertEquals(1, toObject(IntNode.valueOf(1), SchemaBuilder.unionOf().nullType().and().intType().endUnion()));
assertEquals(42.0,
toObject(DoubleNode.valueOf(42.0), SchemaBuilder.unionOf().intType().and().doubleType().endUnion()));
assertEquals("1", toObject(TextNode.valueOf("1"), SchemaBuilder.unionOf().intType().and().stringType().endUnion()));
}

}