Search in sources :

Example 1 with JsonbParser

use of org.eclipse.yasson.internal.JsonbParser in project styx by petafuel.

the class HrefTypeDeserializer method deserialize.

@Override
public Links.Href deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
    JsonValue parsedValue = parser.getValue();
    Links.Href href = new Links.Href();
    if (parsedValue instanceof JsonObject) {
        try (Jsonb jsonb = JsonbBuilder.create()) {
            href = jsonb.fromJson(parsedValue.toString(), Links.Href.class);
        } catch (Exception e) {
            LOG.error("Error trying to deserialize Href", e);
        }
    } else {
        LinkType linkType = null;
        if (parser instanceof JsonbParser) {
            JsonbParser jsonbParser = (JsonbParser) parser;
            linkType = LinkType.getByString(jsonbParser.getCurrentLevel().getLastKeyName());
        }
        href = new Links.Href(parsedValue.toString().replace("\"", ""), linkType);
    }
    return href;
}
Also used : JsonbParser(org.eclipse.yasson.internal.JsonbParser) Jsonb(javax.json.bind.Jsonb) JsonValue(javax.json.JsonValue) Links(net.petafuel.styx.core.xs2a.entities.Links) JsonObject(javax.json.JsonObject) LinkType(net.petafuel.styx.core.xs2a.entities.LinkType)

Aggregations

JsonObject (javax.json.JsonObject)1 JsonValue (javax.json.JsonValue)1 Jsonb (javax.json.bind.Jsonb)1 LinkType (net.petafuel.styx.core.xs2a.entities.LinkType)1 Links (net.petafuel.styx.core.xs2a.entities.Links)1 JsonbParser (org.eclipse.yasson.internal.JsonbParser)1