Java 类javax.json.bind.serializer.DeserializationContext 实例源码

项目:Java-EE-8-Sampler    文件:BookDeserializer.java   
@Override
public Book deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
    Book book = null;
    while (parser.hasNext()) {
        JsonParser.Event event = parser.next();
        if (event == JsonParser.Event.KEY_NAME) {
            String className = parser.getString();
            parser.next();
            try {
                book = ctx.deserialize(Class.forName(className).asSubclass(Book.class), parser);
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        }
    }
    return book;
}
项目:yasson    文件:AdaptedObjectDeserializer.java   
@Override
@SuppressWarnings("unchecked")
public T deserialize(JsonParser parser, DeserializationContext context, Type rtType) {
    Unmarshaller unmarshaller = (Unmarshaller) context;
    unmarshaller.setCurrent(this);
    try {
        unmarshaller.getJsonbContext().addProcessedType(adapterInfo.getBindingType());
        final A result =  adaptedTypeDeserializer.deserialize(parser, context, rtType);
        final T adapted = ((JsonbAdapter<T, A>) adapterInfo.getAdapter()).adaptFromJson(result);
        unmarshaller.setCurrent(wrapperItem);
        return adapted;
    } catch (Exception e) {
        throw new JsonbException(Messages.getMessage(MessageKeys.ADAPTER_EXCEPTION, adapterInfo.getBindingType(), adapterInfo.getToType(), adapterInfo.getAdapter().getClass()), e);
    } finally {
        unmarshaller.getJsonbContext().removeProcessedType(adapterInfo.getBindingType());
    }
}
项目:yasson    文件:JsonValueDeserializer.java   
@Override
public JsonValue deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
    final JsonParser.Event next = ((JsonbRiParser)parser).getLastEvent();
    switch (next) {
        case VALUE_TRUE:
            return JsonValue.TRUE;
        case VALUE_FALSE:
            return JsonValue.FALSE;
        case VALUE_NULL:
            return JsonValue.NULL;
        case VALUE_STRING:
        case VALUE_NUMBER:
            return parser.getValue();
        default:
            throw new JsonbException(Messages.getMessage(MessageKeys.INTERNAL_ERROR, "Unknown JSON value: "+next));
    }
}
项目:johnzon    文件:SerializerTest.java   
@Override
public Foo deserialize(final JsonParser parser, final DeserializationContext ctx, final Type rtType) {
    final Foo f = new Foo();
    assertTrue(parser.hasNext());
    assertEquals(JsonParser.Event.START_OBJECT, parser.next());
    assertTrue(parser.hasNext());
    assertEquals(JsonParser.Event.KEY_NAME, parser.next());
    assertEquals("full", parser.getString());
    assertTrue(parser.hasNext());
    assertEquals(JsonParser.Event.VALUE_TRUE, parser.next());
    assertTrue(parser.hasNext());
    assertEquals(JsonParser.Event.KEY_NAME, parser.next());
    assertEquals("name", parser.getString());
    assertTrue(parser.hasNext());
    assertEquals(JsonParser.Event.VALUE_STRING, parser.next());
    f.name = parser.getString();
    assertTrue(parser.hasNext());
    assertEquals(JsonParser.Event.END_OBJECT, parser.next());

    // to be sure we passed there
    f.flag = true;
    f.value = f.name.length();
    return f;
}
项目:Java-EE-8-Sampler    文件:BookDeserializer.java   
@Override
public String deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
    while (parser.hasNext()) {
        JsonParser.Event event = parser.next();
        if (event == JsonParser.Event.KEY_NAME) {
            String keyName = parser.getString();
            if (keyName.equals("id")) {
                return ctx.deserialize(String.class, parser);
            }
        }
        parser.next();
    }
    return "";
}
项目:yasson    文件:OptionalLongTypeDeserializer.java   
@Override
public OptionalLong deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
    final JsonParser.Event next = ((JsonbParser) parser).moveToValue();
    if (next == JsonParser.Event.VALUE_NULL) {
        return OptionalLong.empty();
    }
    return deserialize(parser.getString(), (Unmarshaller) ctx, rtType);
}
项目:yasson    文件:AbstractValueTypeDeserializer.java   
/**
 * Extracts single string value for conversion.
 *
 * @param parser Parser to get value from.
 * @param ctx Unmarshaller.
 * @param rtType return type.
 * @return Deserialized object.
 */
@Override
public T deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
    Unmarshaller unmarshaller = (Unmarshaller) ctx;
    final JsonParser.Event event = ((JsonbParser) parser).getCurrentLevel().getLastEvent();
    if (event == JsonParser.Event.VALUE_NULL) {
        return null;
    }

    final String value = parser.getString();
    return deserialize(value, unmarshaller, rtType);
}
项目:yasson    文件:OptionalObjectDeserializer.java   
@Override
public Optional<?> deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
    JsonbContext jsonbContext = ((ProcessingContext) ctx).getJsonbContext();
    final JsonParser.Event lastEvent = ((JsonbParser) parser).getCurrentLevel().getLastEvent();
    JsonbDeserializer deserializer = new DeserializerBuilder(jsonbContext).withType(optionalValueType)
            .withWrapper(wrapper).withJsonValueType(lastEvent).build();
    return Optional.of(deserializer.deserialize(parser, ctx, optionalValueType));
}
项目:yasson    文件:BooleanTypeDeserializer.java   
@Override
public Boolean deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
    final JsonParser.Event event = ((JsonbParser) parser).moveToValue();
    switch (event) {
        case VALUE_TRUE:
            return Boolean.TRUE;
        case VALUE_FALSE:
            return Boolean.FALSE;
        case VALUE_STRING:
            return Boolean.parseBoolean(parser.getString());
        default:
            throw new JsonbException(Messages.getMessage(MessageKeys.INTERNAL_ERROR, "Unknown JSON value: " + event));
    }
}
项目:yasson    文件:OptionalIntTypeDeserializer.java   
@Override
public OptionalInt deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
    final JsonParser.Event next = ((JsonbParser) parser).moveToValue();
    if (next == JsonParser.Event.VALUE_NULL) {
        return OptionalInt.empty();
    }
    final String value = parser.getString();
    return deserialize(value, (Unmarshaller) ctx, rtType);
}
项目:yasson    文件:AbstractContainerDeserializer.java   
/**
 * Drives JSONP {@link JsonParser} to deserialize json document.
 *
 * @param parser JSON parser.
 * @param context Deseriaization context.
 * @param rtType Runtime type.
 * @return Instance of a type for this item.
 */
@Override
public final T deserialize(JsonParser parser, DeserializationContext context, Type rtType) {
    Unmarshaller ctx = (Unmarshaller) context;
    ctx.setCurrent(this);
    deserializeInternal((JsonbParser) parser, ctx);
    ctx.setCurrent(getWrapper());
    return getInstance((Unmarshaller) context);
}
项目:yasson    文件:OptionalDoubleTypeDeserializer.java   
@Override
public OptionalDouble deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
    final JsonParser.Event next = ((JsonbParser) parser).moveToValue();
    if (next == JsonParser.Event.VALUE_NULL) {
        return OptionalDouble.empty();
    }
    String value = parser.getString();
    return deserialize(value, (Unmarshaller) ctx, rtType);
}
项目:yasson    文件:SimpleContainerArrayDeserializer.java   
public SimpleContainer[] deserialize(JsonParser jsonParser, DeserializationContext deserializationContext, Type type) {
    List<SimpleContainer> containers = new ArrayList<>();

    while (jsonParser.hasNext()) {
        JsonParser.Event event = jsonParser.next();
        if (event == JsonParser.Event.START_OBJECT) {
            containers.add(deserializationContext.deserialize(new SimpleContainer(){}.getClass().getGenericSuperclass(), jsonParser));
        }
        if (event == JsonParser.Event.END_OBJECT) {
            break;
        }
    }

    return containers.toArray(new SimpleContainer[0]);
}
项目:yasson    文件:CrateJsonObjectDeserializer.java   
/**
 * Deserialize an object from JSON.
 * Cursor of JsonParser is at START_OBJECT.
 *
 * @param parser Json parser
 * @param ctx    Deserialization context
 * @param rtType type of returned object
 * @return deserialized instance
 */
@Override
public Crate deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
    JsonObject crateJsonObject = ctx.deserialize(JsonObject.class, parser);
    Crate crate = new Crate();
    crate.crateInner = new CrateInner();
    crate.crateInner.crateInnerStr = crateJsonObject.getJsonObject("crateInner").getString("crateInnerStr");
    crate.crateInner.crateInnerBigDec = crateJsonObject.getJsonObject("crateInner").getJsonNumber("crateInnerBigDec").bigDecimalValue();
    crate.crateStr = crateJsonObject.getString("crateStr");
    crate.crateBigDec = crateJsonObject.getJsonNumber("crateBigDec").bigDecimalValue();
    return crate;
}
项目:yasson    文件:CrateDeserializer.java   
@Override
    public Crate deserialize(JsonParser jsonParser, DeserializationContext ctx, Type rtType) {
        Crate crate = new Crate();
        crate.crateStr = "abc";
        crate.crateBigDec = new BigDecimal("123");

        while (jsonParser.hasNext()) {
            JsonParser.Event next = jsonParser.next();
            if (next.equals(JsonParser.Event.KEY_NAME) && jsonParser.getString().equals("crateInner")) {
                //invokes JSONB processing for a CrateInner as a root type with "shared" instance of JsonParser
                crate.crateInner = ctx.deserialize(CrateInner.class, jsonParser);
                continue;
            }
            if (next.equals(JsonParser.Event.KEY_NAME) && jsonParser.getString().equals("crateInnerList")) {
                //invokes JSONB processing for a CrateInner as a root type with "shared" instance of JsonParser
                crate.crateInnerList = ctx.deserialize(new TestTypeToken<ArrayList<CrateInner>>(){}.getType(), jsonParser);
                continue;
            }
            if (next.equals(JsonParser.Event.KEY_NAME) && jsonParser.getString().equals("date")) {
                //move to value
                jsonParser.next();
                //don't have context of processing here, no annotation customizations applied.
//                crate.date = ctx.convertDefault(Date.class, jsonParser.getString());
                ctx.deserialize(Date.class, jsonParser);
            }

        }

        return crate;
    }
项目:yasson    文件:CrateDeserializerWithConversion.java   
@Override
public Crate deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
    Crate result = new Crate();
    while (parser.hasNext()) {
        final JsonParser.Event next = parser.next();
        if (next.equals(JsonParser.Event.KEY_NAME) && parser.getString().equals("date-converted")) {
            parser.next();
            result.date = ctx.deserialize(Date.class, parser);
            break;
        }
    }
    return result;
}
项目:johnzon    文件:ClassConverterTest.java   
@Override
public Whole2 deserialize(final JsonParser parser, final DeserializationContext ctx, final Type rtType) {
    parser.next(); // start
    parser.next();
    assertEquals("text", parser.getString());
    parser.next();
    final Whole2 whole2 = new Whole2();
    whole2.name = parser.getString();
    parser.next(); // end
    return whole2;
}
项目:JSON-framework-comparison    文件:CustomDeserializer.java   
@Override
public CompileTimeSampler deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
    return null;
}
项目:yasson    文件:Author.java   
@Override
public String deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
    return "John";
}
项目:yasson    文件:RecursiveDeserializer.java   
@Override
public Box deserialize(JsonParser jsonParser, DeserializationContext deserializationContext, Type type) {
    return deserializationContext.deserialize(type, jsonParser);
}
项目:yasson    文件:AnnotatedWithSerializerTypeDeserializer.java   
/**
 * Deserialize an object from JSON.
 * Cursor of JsonParser is at START_OBJECT.
 *
 * @param parser Json parser
 * @param ctx    Deserialization context
 * @param rtType type of returned object
 * @return deserialized instance
 */
@Override
public AnnotatedWithSerializerType deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
    AnnotatedWithSerializerType result = new AnnotatedWithSerializerType();
    parser.next(); parser.next();
    result.value = parser.getString();
    return result;
}