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:org.deeplearning4j.nn.conf.deserializers.PreProcessorDeSerializer.java

@Override
public OutputPreProcessor deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    JsonNode node = jp.getCodec().readTree(jp);
    String val = node.asText();
    String[] split = val.split("\t");
    if (split.length >= 2) {
        try {//from  w  w  w  . ja va2  s .c  o m
            Class<? extends OutputPreProcessor> clazz2 = (Class<? extends OutputPreProcessor>) Class
                    .forName(split[0]);
            OutputPreProcessor ret = clazz2.newInstance();
            Properties props = new Properties();
            props.load(new StringReader(split[1]));
            Dl4jReflection.setProperties(ret, props);
            return ret;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    return null;
}

From source file:pl.edu.pwr.iiar.zak.thermalKit.util.DBConnector.java

public DBConnector() throws IOException {
    JsonFactory f = new JsonFactory();
    JsonParser jp = f.createParser(new File("~/.jgenerilorc"));
    JsonNode node = jp.getCodec().readTree(jp);

    databaseName = node.get("database").asText();
}

From source file:org.lable.rfc3881.auditlogger.serialization.CodeReferenceDeserializer.java

@Override
public CodeReference deserialize(JsonParser parser, DeserializationContext context) throws IOException {
    ObjectCodec oc = parser.getCodec();
    JsonNode node = oc.readTree(parser);

    // Required fields.
    if (!node.has("cs") || !node.has("code") || !node.has("dn")) {
        return null;
    }/*from   w ww.  jav  a 2s .co m*/
    String codeSystem = node.get("cs").asText(null);
    String code = node.get("code").asText(null);
    String displayName = node.get("dn").asText(null);

    // Optional fields, can be null.
    String codeSystemName = node.has("csn") ? node.get("csn").asText(null) : null;
    String originalText = node.has("ot") ? node.get("ot").asText(null) : null;

    return new CodeReference(codeSystem, codeSystemName, code, displayName, originalText);
}

From source file:com.wavemaker.commons.json.deserializer.HttpHeadersDeSerializer.java

@Override
public HttpHeaders deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    ObjectCodec codec = jp.getCodec();
    ObjectNode root = codec.readTree(jp);
    Map<String, Object> map = ((ObjectMapper) codec).readValue(root.toString(),
            new TypeReference<LinkedHashMap<String, Object>>() {
            });/*w w  w . j  a v  a 2s  .c  om*/
    HttpHeaders httpHeaders = new HttpHeaders();
    for (Map.Entry<String, Object> entry : map.entrySet()) {
        Object value = entry.getValue();
        if (value instanceof String) {
            httpHeaders.add(entry.getKey(), (String) entry.getValue());
        } else if (value instanceof List) {
            httpHeaders.put(entry.getKey(), (List<String>) value);
        }
    }
    return httpHeaders;
}

From source file:com.okta.sdk.models.links.LinksUnionDeserializer.java

@Override
public LinksUnion deserialize(JsonParser parser, DeserializationContext context) throws IOException {
    ObjectMapper mapper = (ObjectMapper) parser.getCodec();
    JsonNode root = mapper.readTree(parser);
    if (root.isArray()) {
        return mapper.convertValue(root, Links.class);
    } else if (root.isObject()) {
        return mapper.convertValue(root, Link.class);
    }//from   www  . j  ava2s.co m
    return null;
}

From source file:org.apache.unomi.persistence.spi.ItemDeserializer.java

@Override
public Item deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    ObjectCodec codec = jp.getCodec();
    ObjectNode treeNode = codec.readTree(jp);
    String type = treeNode.get("itemType").textValue();
    Class<? extends Item> objectClass = classes.get(type);
    if (objectClass == null) {
        objectClass = CustomItem.class;
    } else {//from w  ww.j  a  v a  2 s.  c  o  m
        treeNode.remove("itemType");
    }
    Item item = codec.treeToValue(treeNode, objectClass);
    item.setItemId(treeNode.get("itemId").asText());
    return item;
}

From source file:org.wisdom.monitor.extensions.jcr.script.json.JcrEventDeserializer.java

@Override
public Event deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
    ObjectMapper mapper = (ObjectMapper) p.getCodec();
    JsonNode node = mapper.readTree(p);/*from  www  .ja v a2s  .  c  o m*/
    JcrEvent event = new JcrEvent();
    event.setDate(node.get("date").asLong());
    event.setPath(node.get("path").asText());
    event.setType(node.get("type").asInt());
    event.setUserID(node.get("userID").asText());
    return event;
}

From source file:io.gravitee.definition.jackson.datatype.services.healthcheck.deser.ExpectationDeserializer.java

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

    Expectation expectation = new Expectation();

    final JsonNode assertionsNode = node.get("assertions");
    if (assertionsNode != null) {
        List<String> assertions = new ArrayList<>();
        assertionsNode.elements().forEachRemaining(assertionNode -> assertions.add(assertionNode.asText()));
        expectation.setAssertions(assertions);
    }//from   w ww.jav  a2s.  c  o  m

    if (expectation.getAssertions().isEmpty()) {
        // Add default assertion
        expectation.setAssertions(Collections.singletonList(Expectation.DEFAULT_ASSERTION));
    }

    return expectation;
}

From source file:example.app.core.mapping.json.jackson.serialization.LocalDateDeserializer.java

@Override
public LocalDate deserialize(JsonParser parser, DeserializationContext context) throws IOException {
    JsonNode node = parser.getCodec().readTree(parser);

    int dayOfMonth = node.get("dayOfMonth").asInt();
    int year = node.get("year").asInt();

    Month month = Month.valueOf(node.get("month").asText());

    return LocalDate.of(year, month, dayOfMonth);
}

From source file:io.gravitee.definition.jackson.datatype.services.core.deser.ServiceDeserializer.java

@Override
public Service deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    JsonNode node = jp.getCodec().readTree(jp);
    String serviceName = node.fieldNames().next();

    Class<? extends Service> serviceClass = registeredServices.get(serviceName);
    if (serviceClass == null) {
        return null;
    }/*w  ww . j a  va 2  s.c  o  m*/

    return node.elements().next().traverse(jp.getCodec()).readValueAs(new TypeReference<Service>() {
        @Override
        public Type getType() {
            return serviceClass;
        }
    });
}