javax.json.bind.serializer.DeserializationContext Java Examples

The following examples show how to use javax.json.bind.serializer.DeserializationContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VehicleDeserializer.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Override
public Vehicle deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
    JsonObject json = parser.getObject();
    String type = json.getString("type");
    switch (type) {
        case "CAR":
            Car car = new Car();
            car.type = type;
            car.seatNumber = json.getInt("seatNumber");
            car.name = json.getString("name");
            return car;
        case "MOTO":
            Moto moto = new Moto();
            moto.type = type;
            moto.name = json.getString("name");
            moto.sideCar = json.getBoolean("sideCar");
            return moto;
        default:
            throw new RuntimeException("Type " + type + "not managed");
    }
}
 
Example #2
Source File: BookDeserializer.java    From Java-EE-8-Sampler with MIT License 6 votes vote down vote up
@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;
}
 
Example #3
Source File: Order.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@Override
public StatusEnum deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
    for (StatusEnum b : StatusEnum.values()) {
        if (String.valueOf(b.value).equals(parser.getString())) {
            return b;
        }
    }
    throw new IllegalArgumentException("Unexpected value '" + parser.getString() + "'");
}
 
Example #4
Source File: Pet.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@Override
public StatusEnum deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
    for (StatusEnum b : StatusEnum.values()) {
        if (String.valueOf(b.value).equals(parser.getString())) {
            return b;
        }
    }
    throw new IllegalArgumentException("Unexpected value '" + parser.getString() + "'");
}
 
Example #5
Source File: ObjectIdDeserializer.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectId deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
    String id = parser.getString();
    if (id != null) {
        return new ObjectId(id);
    }
    return null;
}
 
Example #6
Source File: BookDeserializer.java    From Java-EE-8-Sampler with MIT License 5 votes vote down vote up
@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 "";
}
 
Example #7
Source File: AbstractDeserializer.java    From robozonky with Apache License 2.0 5 votes vote down vote up
@Override
public T deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
    try {
        var id = parser.getString();
        return converter.apply(id);
    } catch (final Exception ex) {
        logger.warn("Received unknown value from Zonky: '{}'. This may be a problem, but we continue.",
                parser.getString());
        return defaultValue;
    }
}
 
Example #8
Source File: UserDeserializer.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public User deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
	JsonObject jo = parser.getObject();
	String name = jo.get("name").toString().replace("\"", "");
	if (jo.get("extra") != null) {
		name = name + jo.get("extra").toString().replace("\"", "");
	}
	User u = new User(Integer.parseInt(jo.get("id").toString()), name, null);

	return u;
}
 
Example #9
Source File: ModelWithSerializerAndDeserializerOnField.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public Inner deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
    return new Inner("immutable");
}
 
Example #10
Source File: ZonedDateTimeJsonbConfigCustomizer.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public ZonedDateTime deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
    return ZonedDateTime.of(1988, 11, 17, 0, 0, 0, 0, ZoneId.of("Europe/Paris"));
}
 
Example #11
Source File: VertxJson.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public JsonArray deserialize(JsonParser parser, DeserializationContext context, Type type) {
    JsonArray object = new JsonArray();
    copy(object, parser.getArray());
    return object;
}
 
Example #12
Source File: VertxJson.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public JsonObject deserialize(JsonParser parser, DeserializationContext context, Type type) {
    JsonObject object = new JsonObject();
    copy(object, parser.getObject());
    return object;
}