use of com.linkedin.data.codec.JacksonDataCodec in project rest.li by linkedin.
the class IndentedPdlBuilder method writeJson.
@Override
PdlBuilder writeJson(Object value, DataSchema schema) throws IOException {
if (schema != null) {
JacksonDataTemplateCodec jsonCodec = new JacksonDataTemplateCodec();
jsonCodec.setPrettyPrinter(getPrettyPrinter());
write(toJson(value, jsonCodec, schema));
} else {
JacksonDataCodec jsonCodec = new JacksonDataCodec();
jsonCodec.setPrettyPrinter(getPrettyPrinter());
jsonCodec.setSortKeys(true);
write(toJson(value, jsonCodec));
}
return this;
}
use of com.linkedin.data.codec.JacksonDataCodec in project rest.li by linkedin.
the class TestDataSchema method testEncodeOriginal.
@Test
public void testEncodeOriginal() throws IOException {
SchemaParser parser = new SchemaParser();
parser.parse("{ \"type\": \"record\", \"name\": \"ReferencedFieldType\", \"fields\" : []}");
parser.parse("{ \"type\": \"record\", \"name\": \"ReferencedMapValuesType\", \"fields\" : []}");
parser.parse("{ \"type\": \"record\", \"name\": \"ReferencedArrayItemsType\", \"fields\" : []}");
parser.parse("{ \"type\": \"record\", \"name\": \"ReferencedTyperefType\", \"fields\" : []}");
parser.parse("{ \"type\": \"record\", \"name\": \"ReferencedUnionMemberType\", \"fields\" : []}");
String originalSchemaJson = "{ " + " \"type\": \"record\"," + " \"name\": \"Original\"," + " \"namespace\": \"org.example\"," + " \"package\": \"org.example.packaged\"," + " \"doc\": \"A record\"," + " \"java\": { \"class\": \"org.example.X\", \"coercerClass\": \"org.example.XCoercer\" }," + " \"fields\" : [" + " {\"name\": \"inlineFieldType\", \"type\": { \"type\": \"record\", \"name\": \"Inline\", \"fields\": [] }}," + " {\"name\": \"inlineMapValueType\", \"type\": { \"type\": \"map\", \"values\": { \"type\": \"record\", \"name\": \"InlineValue\", \"fields\": [] } }}," + " {\"name\": \"inlineArrayItemsType\", \"type\": { \"type\": \"array\", \"items\": { \"type\": \"record\", \"name\": \"InlineItems\", \"fields\": [] } }}," + " {\"name\": \"inlineTyperefType\", \"type\": { \"type\": \"typeref\", \"name\": \"InlinedTyperef\", \"ref\": { \"type\": \"record\", \"name\": \"InlineRef\", \"fields\": [] } }}," + " {\"name\": \"inlineUnionType\", \"type\": [ \"string\", { \"type\": \"record\", \"name\": \"InlineUnionMember\", \"fields\": [] } ]}," + " {\"name\": \"inlineUnionTypeWithAliases\", \"type\": [ { \"alias\": \"memString\", \"type\": \"string\" }, { \"alias\": \"memRecord\", \"type\": { \"type\": \"record\", \"name\": \"InlineUnionMember\", \"fields\": [] } } ]}," + " {\"name\": \"referencedFieldType\", \"type\": \"ReferencedFieldType\" }," + " {\"name\": \"referencedMapValueType\", \"type\": { \"type\": \"map\", \"values\": \"ReferencedMapValuesType\" }}," + " {\"name\": \"referencedArrayItemsType\", \"type\": { \"type\": \"array\", \"items\": \"ReferencedArrayItemsType\" }}," + " {\"name\": \"referencedTyperefType\", \"type\": { \"type\": \"typeref\", \"name\": \"ReferencedTyperef\", \"ref\": \"ReferencedTyperefType\" }}," + " {\"name\": \"referencedUnionType\", \"type\": [ \"string\", \"ReferencedUnionMemberType\" ]}," + " {\"name\": \"referencedUnionTypeWithAliases\", \"type\": [ { \"alias\": \"memString\", \"type\": \"string\" }, { \"alias\": \"memRecord\", \"type\": \"ReferencedUnionMemberType\" } ]}" + " ]" + "}";
parser.parse(originalSchemaJson);
DataSchema originalSchema = parser.topLevelDataSchemas().get(parser.topLevelDataSchemas().size() - 1);
JsonBuilder originalBuilder = new JsonBuilder(JsonBuilder.Pretty.INDENTED);
SchemaToJsonEncoder originalEncoder = new SchemaToJsonEncoder(originalBuilder);
originalEncoder.setTypeReferenceFormat(SchemaToJsonEncoder.TypeReferenceFormat.PRESERVE);
originalEncoder.encode(originalSchema);
JacksonDataCodec codec = new JacksonDataCodec();
DataMap original = codec.readMap(new StringReader(originalSchemaJson));
DataMap roundTripped = codec.readMap(new StringReader(originalBuilder.result()));
assertEquals(original, roundTripped);
}
use of com.linkedin.data.codec.JacksonDataCodec in project rest.li by linkedin.
the class TestData method testNonCyclicDuplicates.
@Test
public void testNonCyclicDuplicates() throws Exception {
DataMap root = new DataMap();
DataMap sub = new DataMap();
sub.put("a", "b");
root.put("c", sub);
root.put("d", sub);
new JacksonDataCodec().mapToString(root);
}
use of com.linkedin.data.codec.JacksonDataCodec in project rest.li by linkedin.
the class TestData method testMixedCycleDetection.
@Test(expectedExceptions = IOException.class)
public void testMixedCycleDetection() throws Exception {
DataMap root = new DataMap();
DataList list = new DataList();
list.getUnderlying().add(root);
root.getUnderlying().put("child", list);
new JacksonDataCodec().mapToString(root);
}
use of com.linkedin.data.codec.JacksonDataCodec in project rest.li by linkedin.
the class TestSymbolTableSerializer method data.
@DataProvider
public static Object[][] data() {
List<Object[]> list = new ArrayList<>();
List<DataCodec> codecs = new ArrayList<>();
codecs.add(new BsonDataCodec());
codecs.add(new JacksonDataCodec());
codecs.add(new JacksonSmileDataCodec());
codecs.add(new JacksonLICORDataCodec(false));
codecs.add(new JacksonLICORDataCodec(true));
codecs.add(new ProtobufDataCodec());
for (DataCodec codec : codecs) {
list.add(new Object[] { codec, true });
list.add(new Object[] { codec, false });
}
return list.toArray(new Object[][] {});
}
Aggregations