@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; }
@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()); } }
@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)); } }
@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; }
@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 ""; }
@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); }
/** * 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); }
@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)); }
@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)); } }
@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); }
/** * 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); }
@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); }
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]); }
/** * 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; }
@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; }
@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; }
@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; }
@Override public CompileTimeSampler deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) { return null; }
@Override public String deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) { return "John"; }
@Override public Box deserialize(JsonParser jsonParser, DeserializationContext deserializationContext, Type type) { return deserializationContext.deserialize(type, jsonParser); }
/** * 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; }