Search in sources :

Example 6 with JacksonDataCodec

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;
}
Also used : JacksonDataCodec(com.linkedin.data.codec.JacksonDataCodec) JacksonDataTemplateCodec(com.linkedin.data.template.JacksonDataTemplateCodec)

Example 7 with JacksonDataCodec

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);
}
Also used : JacksonDataCodec(com.linkedin.data.codec.JacksonDataCodec) StringReader(java.io.StringReader) ByteString(com.linkedin.data.ByteString) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 8 with JacksonDataCodec

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);
}
Also used : JacksonDataCodec(com.linkedin.data.codec.JacksonDataCodec) Test(org.testng.annotations.Test)

Example 9 with JacksonDataCodec

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);
}
Also used : JacksonDataCodec(com.linkedin.data.codec.JacksonDataCodec) Test(org.testng.annotations.Test)

Example 10 with JacksonDataCodec

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[][] {});
}
Also used : JacksonSmileDataCodec(com.linkedin.data.codec.JacksonSmileDataCodec) ProtobufDataCodec(com.linkedin.data.codec.ProtobufDataCodec) DataCodec(com.linkedin.data.codec.DataCodec) JacksonLICORDataCodec(com.linkedin.data.codec.JacksonLICORDataCodec) JacksonDataCodec(com.linkedin.data.codec.JacksonDataCodec) BsonDataCodec(com.linkedin.data.codec.BsonDataCodec) JacksonDataCodec(com.linkedin.data.codec.JacksonDataCodec) ProtobufDataCodec(com.linkedin.data.codec.ProtobufDataCodec) JacksonLICORDataCodec(com.linkedin.data.codec.JacksonLICORDataCodec) BsonDataCodec(com.linkedin.data.codec.BsonDataCodec) ArrayList(java.util.ArrayList) JacksonSmileDataCodec(com.linkedin.data.codec.JacksonSmileDataCodec) DataProvider(org.testng.annotations.DataProvider)

Aggregations

JacksonDataCodec (com.linkedin.data.codec.JacksonDataCodec)27 Test (org.testng.annotations.Test)16 IOException (java.io.IOException)7 DataMap (com.linkedin.data.DataMap)6 BeforeTest (org.testng.annotations.BeforeTest)5 BackupRequestsConfiguration (com.linkedin.d2.BackupRequestsConfiguration)3 BoundedCostBackupRequests (com.linkedin.d2.BoundedCostBackupRequests)3 DataCodec (com.linkedin.data.codec.DataCodec)3 ByteString (com.linkedin.data.ByteString)2 BsonDataCodec (com.linkedin.data.codec.BsonDataCodec)2 PsonDataCodec (com.linkedin.data.codec.PsonDataCodec)2 EmptyRecord (com.linkedin.restli.common.EmptyRecord)2 BufferedReader (java.io.BufferedReader)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileOutputStream (java.io.FileOutputStream)2 InputStreamReader (java.io.InputStreamReader)2 PrintStream (java.io.PrintStream)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 TestUtil.dataMapFromString (com.linkedin.data.TestUtil.dataMapFromString)1