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:com.pkrete.locationservice.admin.deserializers.JSJSONDeserializer.java

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

    ObjectCodec oc = jsonParser.getCodec();
    JsonNode node = oc.readTree(jsonParser);
    // Parse id/*from  w ww  .j  av  a  2  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 JS
    return new JS(id, filename, "", contents, null);
}

From source file:org.echocat.marquardt.common.serialization.PublicKeyDeserializer.java

@Override
public PublicKey deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext)
        throws IOException {
    final ObjectCodec oc = jsonParser.getCodec();
    final JsonNode node = oc.readTree(jsonParser);
    return new PublicKeyWithMechanism(node.get(PublicKeySerializer.KEY).binaryValue()).toJavaKey();
}

From source file:com.btmatthews.atlas.core.dao.mongo.MongoLocalDateTimeDeserializer.java

@Override
public LocalDateTime deserialize(final JsonParser parser, final DeserializationContext context)
        throws IOException {
    final ObjectCodec codec = parser.getCodec();
    final JsonNode node = codec.readTree(parser);
    final JsonNode dateNode = node.get("$date");
    return LocalDateTime.parse(dateNode.asText(), DATE_TIME_FORMATTER);
}

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

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

    HttpClient httpClient = new HttpClient();

    JsonNode httpProxyNode = node.get("http_proxy");
    if (httpProxyNode != null) {
        HttpProxy httpProxy = httpProxyNode.traverse(jp.getCodec()).readValueAs(HttpProxy.class);
        httpClient.setHttpProxy(httpProxy);
    }/*from  ww w.jav a  2  s  . c  om*/

    JsonNode httpClientOptionsNode = node.get("configuration");
    if (httpClientOptionsNode != null) {
        HttpClientOptions httpClientOptions = httpClientOptionsNode.traverse(jp.getCodec())
                .readValueAs(HttpClientOptions.class);
        httpClient.setOptions(httpClientOptions);
    }

    JsonNode httpClientSslOptionsNode = node.get("ssl");
    if (httpClientSslOptionsNode != null) {
        HttpClientSslOptions httpClientSslOptions = httpClientSslOptionsNode.traverse(jp.getCodec())
                .readValueAs(HttpClientSslOptions.class);
        httpClient.setSsl(httpClientSslOptions);
    }

    return httpClient;
}

From source file:bz.tsung.jsonapi4j.serialization.DataDeserializer.java

@Override
public Data<Resource> deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException {
    JsonNode node = jsonParser.getCodec().readTree(jsonParser);
    ObjectMapper mapper = new MappingJsonFactory().getCodec();
    if (node.isArray()) {
        List<Resource> resources = new ArrayList<Resource>();
        for (JsonNode n : node) {
            Resource r = mapper.readValue(n.toString(), Resource.class);
            resources.add(r);//from  w  w  w.  j  av  a 2 s  .  c o  m
        }
        return new Data<Resource>(resources);
    }
    Resource resource = mapper.readValue(node.toString(), Resource.class);
    return new Data<Resource>(resource);
}

From source file:org.calrissian.mango.json.deser.BaseTupleStoreDeserializer.java

@Override
public T deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
    JsonNode root = jsonParser.getCodec().readTree(jsonParser);
    T tupleStore = deserialize(root);//  w  w w .  j a v a2  s .c o  m

    ObjectNode tuplesObject = (ObjectNode) root.get("tuples");

    Map<String, Collection<Tuple>> tuples = jsonParser.getCodec()
            .readValue(jsonParser.getCodec().treeAsTokens(tuplesObject), TR);

    tupleStore.putAll(concat(tuples.values()));

    return tupleStore;

}

From source file:br.com.hyperclass.snackbar.restapi.deserializer.SalesDateDeserialize.java

@Override
public SalesDateWrapper deserialize(JsonParser jsonParser, DeserializationContext context)
        throws IOException, JsonProcessingException {

    ObjectCodec oc = jsonParser.getCodec();
    JsonNode node = oc.readTree(jsonParser);

    return new SalesDateWrapper(node.get("dateInitial").asLong(), node.get("dateFinal").asLong());
}

From source file:com.evrythng.java.wrapper.mapping.ActionDeserializerImpl.java

@Override
public Action deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException {

    ObjectCodec codec = jp.getCodec();
    ObjectMapper mapper = (ObjectMapper) codec;
    ObjectNode root = mapper.readTree(jp);
    JsonNode type = root.get(getTypeFieldName());
    if (type == null) {
        throw new IllegalArgumentException(this.getValueClass().getSimpleName() + " type cannot be empty.");
    }/*from w w w .  j  a  v a 2  s .  co m*/
    String sType = type.textValue();
    if (sType == null || sType.isEmpty()) {
        throw new IllegalArgumentException(this.getValueClass().getSimpleName() + " type cannot be empty.");
    }

    return codec.treeToValue(root, resolveClass(sType));
}

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

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

    ObjectCodec oc = jsonParser.getCodec();
    JsonNode node = oc.readTree(jsonParser);
    int id = node.get("id") == null ? 0 : node.get("id").intValue();
    String name = node.get("name") == null ? "" : node.get("name").textValue();
    String code = node.get("code") == null ? "" : node.get("code").textValue();
    return new Language(id, name, code);
}

From source file:com.yahoo.elide.jsonapi.serialization.DataDeserializer.java

@Override
public Data<Resource> deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException {
    JsonNode node = jsonParser.getCodec().readTree(jsonParser);
    ObjectMapper mapper = new MappingJsonFactory().getCodec();
    if (node.isArray()) {
        List<Resource> resources = new ArrayList<>();
        for (JsonNode n : node) {
            Resource r = mapper.convertValue(n, Resource.class);
            resources.add(r);/*from  w  ww.  j a  v  a 2s.c  om*/
        }
        return new Data<>(resources);
    }
    Resource resource = mapper.convertValue(node, Resource.class);
    return new Data<>(resource);
}