예제 #1
0
 public void testEmbeddedObject() throws Exception {
   TokenBuffer buf = new TokenBuffer(MAPPER);
   buf.writeObject(new byte[3]);
   JsonNode node = MAPPER.readTree(buf.asParser());
   buf.close();
   assertTrue(node.isBinary());
   byte[] data = node.binaryValue();
   assertNotNull(data);
   assertEquals(3, data.length);
 }
예제 #2
0
 @SuppressWarnings("unchecked")
 public <T extends JsonNode> T valueToTree(ObjectWriter writer, Object fromValue)
     throws IllegalArgumentException {
   if (fromValue == null) return null;
   TokenBuffer buf = new TokenBuffer(mapper);
   JsonNode result;
   try {
     writer.writeValue(buf, fromValue);
     JsonParser jp = buf.asParser();
     result = mapper.readTree(jp);
     jp.close();
   } catch (IOException e) { // should not occur, no real i/o...
     throw new IllegalArgumentException(e.getMessage(), e);
   }
   return (T) result;
 }
 private final Object _deserialize(
     JsonParser paramJsonParser, DeserializationContext paramDeserializationContext)
     throws IOException {
   Object localObject1;
   if (paramJsonParser.canReadTypeId()) {
     localObject1 = paramJsonParser.getTypeId();
     if (localObject1 != null) {
       paramJsonParser =
           _deserializeWithNativeTypeId(
               paramJsonParser, paramDeserializationContext, localObject1);
     }
   }
   do {
     boolean bool;
     Object localObject2;
     do {
       return paramJsonParser;
       bool = paramJsonParser.isExpectedStartArrayToken();
       String str = _locateTypeId(paramJsonParser, paramDeserializationContext);
       localObject2 = _findDeserializer(paramDeserializationContext, str);
       localObject1 = paramJsonParser;
       if (this._typeIdVisible) {
         localObject1 = paramJsonParser;
         if (paramJsonParser.getCurrentToken() == JsonToken.START_OBJECT) {
           localObject1 = new TokenBuffer(null, false);
           ((TokenBuffer) localObject1).writeStartObject();
           ((TokenBuffer) localObject1).writeFieldName(this._typePropertyName);
           ((TokenBuffer) localObject1).writeString(str);
           localObject1 =
               JsonParserSequence.createFlattened(
                   ((TokenBuffer) localObject1).asParser(paramJsonParser), paramJsonParser);
           ((JsonParser) localObject1).nextToken();
         }
       }
       localObject2 =
           ((JsonDeserializer) localObject2)
               .deserialize((JsonParser) localObject1, paramDeserializationContext);
       paramJsonParser = (JsonParser) localObject2;
     } while (!bool);
     paramJsonParser = (JsonParser) localObject2;
   } while (((JsonParser) localObject1).nextToken() == JsonToken.END_ARRAY);
   throw paramDeserializationContext.wrongTokenException(
       (JsonParser) localObject1,
       JsonToken.END_ARRAY,
       "expected closing END_ARRAY after type information and deserialized value");
 }
예제 #4
0
 public void testEmbeddedObjectInObject() throws Exception {
   TokenBuffer buf = new TokenBuffer(MAPPER);
   buf.writeStartObject();
   buf.writeFieldName("pojo");
   buf.writeObject(MARKER);
   buf.writeEndObject();
   JsonNode node = MAPPER.readTree(buf.asParser());
   buf.close();
   assertTrue(node.isObject());
   assertEquals(1, node.size());
   JsonNode n = node.get("pojo");
   assertTrue(n.isPojo());
   assertSame(MARKER, ((POJONode) n).getPojo());
 }
 public void serialize(
     TokenBuffer paramTokenBuffer,
     JsonGenerator paramJsonGenerator,
     SerializerProvider paramSerializerProvider) {
   paramTokenBuffer.serialize(paramJsonGenerator);
 }
예제 #6
0
 public void serialize(
     TokenBuffer tokenbuffer, JsonGenerator jsongenerator, SerializerProvider serializerprovider)
     throws IOException, JsonGenerationException {
   tokenbuffer.serialize(jsongenerator);
 }