Search in sources :

Example 11 with ObjectCodec

use of com.fasterxml.jackson.core.ObjectCodec in project druid by druid-io.

the class AggregationTestHelper method readQueryResultArrayFromString.

private List readQueryResultArrayFromString(String str) throws Exception {
    List result = new ArrayList();
    JsonParser jp = mapper.getFactory().createParser(str);
    if (jp.nextToken() != JsonToken.START_ARRAY) {
        throw new IAE("not an array [%s]", str);
    }
    ObjectCodec objectCodec = jp.getCodec();
    while (jp.nextToken() != JsonToken.END_ARRAY) {
        result.add(objectCodec.readValue(jp, toolChest.getResultTypeReference()));
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ObjectCodec(com.fasterxml.jackson.core.ObjectCodec) IAE(io.druid.java.util.common.IAE) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 12 with ObjectCodec

use of com.fasterxml.jackson.core.ObjectCodec in project ratpack by ratpack.

the class ServerConfigDataDeserializer method deserialize.

@Override
public ServerConfigData deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    ObjectCodec codec = jp.getCodec();
    ObjectNode serverNode = jp.readValueAsTree();
    ServerConfigData data = new ServerConfigData(baseDirSupplier.get(), address, port, development, publicAddress);
    if (serverNode.hasNonNull("port")) {
        data.setPort(parsePort(serverNode.get("port")));
    }
    if (serverNode.hasNonNull("address")) {
        data.setAddress(toValue(codec, serverNode.get("address"), InetAddress.class));
    }
    if (serverNode.hasNonNull("development")) {
        data.setDevelopment(serverNode.get("development").asBoolean(false));
    }
    if (serverNode.hasNonNull("threads")) {
        data.setThreads(serverNode.get("threads").asInt(ServerConfig.DEFAULT_THREADS));
    }
    if (serverNode.hasNonNull("publicAddress")) {
        data.setPublicAddress(toValue(codec, serverNode.get("publicAddress"), URI.class));
    }
    if (serverNode.hasNonNull("maxContentLength")) {
        data.setMaxContentLength(serverNode.get("maxContentLength").asInt(ServerConfig.DEFAULT_MAX_CONTENT_LENGTH));
    }
    if (serverNode.hasNonNull("maxChunkSize")) {
        data.setMaxChunkSize(serverNode.get("maxChunkSize").asInt(ServerConfig.DEFAULT_MAX_CHUNK_SIZE));
    }
    if (serverNode.hasNonNull("maxInitialLineLength")) {
        data.setMaxInitialLineLength(serverNode.get("maxInitialLineLength").asInt(ServerConfig.DEFAULT_MAX_INITIAL_LINE_LENGTH));
    }
    if (serverNode.hasNonNull("maxHeaderSize")) {
        data.setMaxHeaderSize(serverNode.get("maxHeaderSize").asInt(ServerConfig.DEFAULT_MAX_HEADER_SIZE));
    }
    if (serverNode.hasNonNull("ssl")) {
        data.setSslContext(toValue(codec, serverNode.get("ssl"), SSLContext.class));
    }
    if (serverNode.hasNonNull("requireClientSslAuth")) {
        data.setRequireClientSslAuth(serverNode.get("requireClientSslAuth").asBoolean(false));
    }
    if (serverNode.hasNonNull("baseDir")) {
        throw new IllegalStateException("baseDir value cannot be set via config, it must be set directly via ServerConfigBuilder.baseDir()");
    }
    if (serverNode.hasNonNull("connectTimeoutMillis")) {
        parseOptionalIntValue("connectTimeoutMillis", serverNode.get("connectTimeoutMillis")).ifPresent(data::setConnectTimeoutMillis);
    }
    if (serverNode.hasNonNull("maxMessagesPerRead")) {
        parseOptionalIntValue("maxMessagesPerRead", serverNode.get("maxMessagesPerRead")).ifPresent(data::setMaxMessagesPerRead);
    }
    if (serverNode.hasNonNull("receiveBufferSize")) {
        parseOptionalIntValue("receiveBufferSize", serverNode.get("receiveBufferSize")).ifPresent(data::setReceiveBufferSize);
    }
    if (serverNode.hasNonNull("writeSpinCount")) {
        parseOptionalIntValue("writeSpinCount", serverNode.get("writeSpinCount")).ifPresent(data::setWriteSpinCount);
    }
    return data;
}
Also used : ServerConfigData(ratpack.server.internal.ServerConfigData) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ObjectCodec(com.fasterxml.jackson.core.ObjectCodec) SSLContext(javax.net.ssl.SSLContext) InetAddress(java.net.InetAddress) URI(java.net.URI)

Example 13 with ObjectCodec

use of com.fasterxml.jackson.core.ObjectCodec in project Rosetta by HubSpot.

the class RosettaModule method setupModule.

@Override
public void setupModule(SetupContext context) {
    context.addBeanSerializerModifier(new StoredAsJsonBeanSerializerModifier());
    ObjectCodec codec = context.getOwner();
    if (codec instanceof ObjectMapper) {
        ObjectMapper mapper = (ObjectMapper) codec;
        context.insertAnnotationIntrospector(new RosettaAnnotationIntrospector(mapper));
        mapper.setSerializerProvider(new DefaultSerializerProvider.Impl());
        mapper.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false);
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    }
}
Also used : DefaultSerializerProvider(com.fasterxml.jackson.databind.ser.DefaultSerializerProvider) ObjectCodec(com.fasterxml.jackson.core.ObjectCodec) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 14 with ObjectCodec

use of com.fasterxml.jackson.core.ObjectCodec in project shifu by ShifuML.

the class RunModeDeserializer method deserialize.

@Override
public RunMode deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    ObjectCodec oc = jp.getCodec();
    JsonNode node = oc.readTree(jp);
    for (RunMode value : RunMode.values()) {
        if (value.name().equalsIgnoreCase(node.textValue())) {
            return value;
        }
    }
    return null;
}
Also used : RunMode(ml.shifu.shifu.container.obj.ModelBasicConf.RunMode) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectCodec(com.fasterxml.jackson.core.ObjectCodec)

Example 15 with ObjectCodec

use of com.fasterxml.jackson.core.ObjectCodec in project shifu by ShifuML.

the class SouceTypeDeserializer method deserialize.

@Override
public SourceType deserialize(JsonParser jp, DeserializationContext context) throws IOException {
    ObjectCodec oc = jp.getCodec();
    JsonNode node = oc.readTree(jp);
    for (SourceType value : SourceType.values()) {
        if (value.name().equalsIgnoreCase(node.textValue())) {
            return value;
        }
    }
    return null;
}
Also used : SourceType(ml.shifu.shifu.container.obj.RawSourceData.SourceType) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectCodec(com.fasterxml.jackson.core.ObjectCodec)

Aggregations

ObjectCodec (com.fasterxml.jackson.core.ObjectCodec)21 JsonNode (com.fasterxml.jackson.databind.JsonNode)18 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ArrayList (java.util.ArrayList)2 GeoJsonPoint (org.springframework.data.mongodb.core.geo.GeoJsonPoint)2 JsonParser (com.fasterxml.jackson.core.JsonParser)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 DefaultSerializerProvider (com.fasterxml.jackson.databind.ser.DefaultSerializerProvider)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 IAE (io.druid.java.util.common.IAE)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 URI (java.net.URI)1 X509Certificate (java.security.cert.X509Certificate)1 List (java.util.List)1 SSLContext (javax.net.ssl.SSLContext)1 RunMode (ml.shifu.shifu.container.obj.ModelBasicConf.RunMode)1