Example usage for com.fasterxml.jackson.core JsonParser getCodec

List of usage examples for com.fasterxml.jackson.core JsonParser getCodec

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core JsonParser getCodec.

Prototype

public abstract ObjectCodec getCodec();

Source Link

Document

Accessor for ObjectCodec associated with this parser, if any.

Usage

From source file:de.dfki.asr.compass.rest.serialization.AbstractIDToEntityDeserializer.java

@Override
public EntityType deserialize(final JsonParser jp, final DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    ObjectCodec oc = jp.getCodec();
    Long id = oc.readValue(jp, new TypeReference<Long>() {
    });//ww  w  .  ja va2  s  .c om
    try {
        return referenceById(id);
    } catch (EntityNotFoundException e) {
        throw new IOException("Cannot load from Database", e);
    }
}

From source file:io.gravitee.definition.jackson.datatype.api.deser.HttpProxyDeserializer.java

@Override
public HttpProxy deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    JsonNode node = jp.getCodec().readTree(jp);

    HttpProxy httpProxy = new HttpProxy();

    JsonNode enabledNode = node.get("enabled");
    if (enabledNode != null) {
        boolean enabled = enabledNode.asBoolean(false);
        httpProxy.setEnabled(enabled);// w w w  .  ja  v  a 2 s .c o  m
    }

    httpProxy.setHost(readStringValue(node, "host"));

    String sPort = readStringValue(node, "port");
    if (sPort != null) {
        httpProxy.setPort(Integer.parseInt(sPort));
    }

    httpProxy.setPassword(readStringValue(node, "password"));
    httpProxy.setUsername(readStringValue(node, "username"));

    final JsonNode typeNode = node.get("type");
    if (typeNode != null) {
        httpProxy.setType(HttpProxyType.valueOf(typeNode.asText().toUpperCase()));
    }

    return httpProxy;
}

From source file:com.centurylink.cloud.sdk.policy.services.client.domain.ActionSettingsDeserializer.java

@Override
public ActionSettingsMetadata deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException {
    TreeNode node = jsonParser.getCodec().readTree(jsonParser);

    //email settings
    if (node.get(RECIPIENTS).isArray()) {
        ArrayNode recipientsNode = ((ArrayNode) node.get(RECIPIENTS));
        List<String> recipients = new ArrayList<>(recipientsNode.size());

        recipientsNode.forEach(recipient -> recipients.add(recipient.asText()));

        return new ActionSettingsEmailMetadata().recipients(recipients);
    }//from  www .j  av  a2s  .  c  o m
    return null;
}

From source file:ml.shifu.shifu.container.obj.BinningMethodDeserializer.java

@Override
public BinningMethod deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    ObjectCodec oc = jp.getCodec();
    JsonNode node = oc.readTree(jp);/*www . j av  a 2s .co  m*/

    for (BinningMethod value : BinningMethod.values()) {
        if (value.name().equalsIgnoreCase(node.textValue())) {
            return value;
        }
    }
    return null;
}

From source file:de.dfki.asr.compass.rest.serialization.RenderGeometryDeserializer.java

@Override
public RenderGeometry deserialize(final JsonParser jp, final DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    ObjectCodec oc = jp.getCodec();
    Long id = oc.readValue(jp, new TypeReference<Long>() {
    });/*from  ww w . j a va 2s  .  c o m*/
    try {
        return (RenderGeometry) manager.referenceById(id);
    } catch (EntityNotFoundException e) {
        throw new IOException("Cannot load from Database", e);
    }
}

From source file:de.fraunhofer.iosb.ilt.sta.deserialize.TimeInstantDeserializer.java

@Override
public TimeInstant deserialize(JsonParser jp, DeserializationContext dc)
        throws IOException, JsonProcessingException {
    return TimeInstant.parse(((JsonNode) jp.getCodec().readTree(jp)).asText());
}

From source file:com.pkrete.locationservice.admin.deserializers.CSSJSONDeserializer.java

@Override
public CSS deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException {

    ObjectCodec oc = jsonParser.getCodec();
    JsonNode node = oc.readTree(jsonParser);
    // Parse id//ww  w .j a  v a2  s  .c  o  m
    int id = node.get("id") == null ? 0 : node.get("id").intValue();
    // Parse filename
    String filename = node.get("filename") == null ? "" : node.get("filename").textValue();
    // Parse contents
    String contents = node.get("contents") == null ? null : node.get("contents").textValue();

    // Return new CSS
    return new CSS(id, filename, "", contents, null);
}

From source file:de.fraunhofer.iosb.ilt.sta.deserialize.TimeIntervalDeserializer.java

@Override
public TimeInterval deserialize(JsonParser jp, DeserializationContext dc)
        throws IOException, JsonProcessingException {
    return TimeInterval.parse(((JsonNode) jp.getCodec().readTree(jp)).asText());
}

From source file:de.dfki.asr.compass.rest.serialization.ReferenceDeserializer.java

@Override
public EntityClass deserialize(final JsonParser jp, final DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    ObjectCodec oc = jp.getCodec();
    Long id = oc.readValue(jp, new TypeReference<Long>() {
    });/*  w  ww .ja v  a 2s  .  com*/
    try {
        return manager.referenceById(id);
    } catch (EntityNotFoundException e) {
        throw new IOException("Cannot load from Database", e);
    }
}

From source file:io.gravitee.definition.jackson.datatype.plugins.resource.deser.ResourceDeserializer.java

@Override
public Resource deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    JsonNode node = jp.getCodec().readTree(jp);

    Resource resource = new Resource();

    final JsonNode nameNode = node.get("name");
    if (nameNode != null) {
        resource.setName(nameNode.asText());
    } else {/*from   w w w.j  a  v  a 2s.c o  m*/
        throw ctxt.mappingException("[resource] Name is required");
    }

    final JsonNode typeNode = node.get("type");
    if (typeNode != null) {
        resource.setType(typeNode.asText());
    } else {
        throw ctxt.mappingException("[resource] Type is required");
    }

    final JsonNode configurationNode = node.get("configuration");
    if (configurationNode != null) {
        resource.setConfiguration(configurationNode.toString());
    } else {
        throw ctxt.mappingException("[resource] Configuration is required");
    }

    final JsonNode enabledNode = node.get("enabled");
    if (enabledNode != null) {
        resource.setEnabled(enabledNode.asBoolean(true));
    } else {
        resource.setEnabled(true);
    }

    return resource;
}