Package com.linkedin.data.codec

Examples of com.linkedin.data.codec.JacksonDataCodec$Parser


  public static DataMap dataSchemaToDataMap(NamedDataSchema schema)
  {
    String inputSchemaAsString = schema.toString();
    try
    {
      JacksonDataCodec codec = new JacksonDataCodec();
      DataMap schemaAsDataMap = codec.stringToMap(inputSchemaAsString);
      return schemaAsDataMap;
    }
    catch (IOException e)
    {
      // This should never occur.
View Full Code Here


   */
  public static DataSchema dataMapToDataSchema(DataMap map, SchemaParser parser)
  {
    // Convert DataMap into DataSchema
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    JacksonDataCodec codec = new JacksonDataCodec();
    try
    {
      codec.writeMap(map, outputStream);
    }
    catch (IOException e)
    {
      // This should never occur
      throw new IllegalStateException(UNEXPECTED_IOEXCEPTION + map, e);
View Full Code Here

  }

  @Test
  public void testJacksonDataCodec() throws IOException
  {
    JacksonDataCodec codec = new JacksonDataCodec();
    testDataCodec(codec, referenceDataMap1);

    DataList list1 = codec.bytesToList("[7,27,279]".getBytes());
    assertEquals(list1, new DataList(Arrays.asList(7, 27, 279)));

    DataList list2 = new DataList(Arrays.asList(321, 21, 1));
    assertEquals(codec.listToBytes(list2), "[321,21,1]".getBytes());

    DataMap map3 = getMapFromJson(codec, "{ \"a\" : null }");
    // out.println(map3.getError());
    assertSame(map3.get("a"), Data.NULL);

    DataMap map4 = getMapFromJson(codec, "{ \"b\" : 123456789012345678901234567890 }");
    // out.println(map4.getError());
    assertTrue(map4.getError().indexOf(" value: 123456789012345678901234567890, token: VALUE_NUMBER_INT, number type: BIG_INTEGER not parsed.") != -1);

    DataMap map5 = getMapFromJson(codec, "{ \"a\" : null, \"b\" : 123456789012345678901234567890 }");
    // out.println(map5.getError());
    assertTrue(map5.getError().indexOf(" value: 123456789012345678901234567890, token: VALUE_NUMBER_INT, number type: BIG_INTEGER not parsed.") != -1);

    // Test comments
    codec.setAllowComments(true);
    DataMap map6 = getMapFromJson(codec, "/* abc */ { \"a\" : \"b\" }");
    assertEquals(map6.get("a"), "b");

    // Test getStringEncoding
    String encoding = codec.getStringEncoding();
    assertEquals(encoding, "UTF-8");
    assertEquals(encoding, JsonEncoding.UTF8.getJavaName());
  }
View Full Code Here

  }

  @Test
  public void testJacksonCodecNumbers() throws IOException
  {
    JacksonDataCodec codec = new JacksonDataCodec();
    testCodecNumbers(codec);
  }
View Full Code Here

  }

  @Test(expectedExceptions = IOException.class)
  public void testJacksonDataCodecErrorEmptyInput() throws IOException
  {
    final JacksonDataCodec codec = new JacksonDataCodec();
    final ByteArrayInputStream in = new ByteArrayInputStream(new byte[0]);
    codec.readMap(in);
  }
View Full Code Here

  }

  @Test(expectedExceptions = DataDecodingException.class)
  public void testJacksonDataCodecErrorToList() throws IOException
  {
    final JacksonDataCodec codec = new JacksonDataCodec();
    codec.bytesToList("{\"A\": 1}".getBytes());
  }
View Full Code Here

  }

  @Test(expectedExceptions = DataDecodingException.class)
  public void testJacksonDataCodecErrorToMap() throws IOException
  {
    final JacksonDataCodec codec = new JacksonDataCodec();
    codec.bytesToMap("[1, 2, 3]".getBytes());
  }
View Full Code Here

  }

  private void perfTest(int count, DataMap map) throws IOException
  {
    List<DataCodec> codecs = new ArrayList<DataCodec>();
    codecs.add(new JacksonDataCodec());
    //codecs.add(new Bson4JacksonDataCodec());
    codecs.add(new BsonDataCodec());

    for (DataCodec codec : codecs)
    {
View Full Code Here

{
  protected boolean debug = false;

  public Object jsonToObject(String s) throws IOException
  {
    JacksonDataCodec codec = new JacksonDataCodec();
    String input = "{ \"key\" : " + s + " }";
    DataMap map = TestUtil.dataMapFromString(input);
    return map.get("key");
  }
View Full Code Here

  @Test
  public void run() throws IOException
  {
    DataCodec codecs[] = {
      new JacksonDataCodec(),
      new PsonDataCodec().setOptions(new PsonDataCodec.Options().setEncodeCollectionCount(false).setEncodeStringLength(false)),
      new PsonDataCodec().setOptions(new PsonDataCodec.Options().setEncodeCollectionCount(false).setEncodeStringLength(true)),
      new PsonDataCodec().setOptions(new PsonDataCodec.Options().setEncodeCollectionCount(true).setEncodeStringLength(false)),
      new PsonDataCodec().setOptions(new PsonDataCodec.Options().setEncodeCollectionCount(true).setEncodeStringLength(true)),
    };
View Full Code Here

TOP

Related Classes of com.linkedin.data.codec.JacksonDataCodec$Parser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.