Search in sources :

Example 31 with JsonParser

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParser in project ksql by confluentinc.

the class ArrayContainsKudf method jsonStringArrayContains.

private boolean jsonStringArrayContains(Object searchValue, String jsonArray) {
    JsonToken valueType = getType(searchValue);
    try (JsonParser parser = JSON_FACTORY.createParser(jsonArray)) {
        if (parser.nextToken() != START_ARRAY) {
            return false;
        }
        while (parser.currentToken() != null) {
            JsonToken token = parser.nextToken();
            if (token == null) {
                return searchValue == null;
            }
            if (token == END_ARRAY) {
                return false;
            }
            parser.skipChildren();
            if (valueType == token) {
                final Matcher matcher = matchers.get(valueType);
                if (matcher != null && matcher.matches(parser, searchValue)) {
                    return true;
                }
            }
        }
    } catch (IOException e) {
        throw new KsqlException("Invalid JSON format: " + jsonArray, e);
    }
    return false;
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken) IOException(java.io.IOException) KsqlException(io.confluent.ksql.util.KsqlException) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 32 with JsonParser

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParser in project faf-java-server by FAForever.

the class LegacyRequestTransformer method handleJsonStats.

private ClientMessage handleJsonStats(Map<String, Object> source) {
    return noCatch(() -> {
        JsonNode node = objectMapper.readTree((String) getArgs(source).get(0));
        JsonNode stats = node.get("stats");
        TypeReference<List<ArmyStatistics>> typeReference = new TypeReference<List<ArmyStatistics>>() {
        };
        JsonParser jsonParser = stats.traverse();
        jsonParser.setCodec(objectMapper);
        return new ArmyStatisticsReport(jsonParser.readValueAs(typeReference));
    });
}
Also used : ArmyStatistics(com.faforever.server.stats.ArmyStatistics) ArmyStatisticsReport(com.faforever.server.stats.ArmyStatisticsReport) JsonNode(com.fasterxml.jackson.databind.JsonNode) List(java.util.List) TypeReference(com.fasterxml.jackson.core.type.TypeReference) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 33 with JsonParser

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParser in project faf-java-server by FAForever.

the class ArmyStatisticsServiceTest method readStats.

private List<ArmyStatistics> readStats(String file) throws java.io.IOException {
    JsonNode node = objectMapper.readTree(getClass().getResourceAsStream(file));
    JsonNode stats = node.get("stats");
    TypeReference<List<ArmyStatistics>> typeReference = new TypeReference<List<ArmyStatistics>>() {
    };
    JsonParser jsonParser = stats.traverse();
    jsonParser.setCodec(objectMapper);
    return jsonParser.readValueAs(typeReference);
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayList(java.util.ArrayList) List(java.util.List) TypeReference(com.fasterxml.jackson.core.type.TypeReference) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 34 with JsonParser

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParser in project java by wavefrontHQ.

the class JsonMetricsGenerator method generateJsonMetrics.

public static JsonNode generateJsonMetrics(MetricsRegistry registry, boolean includeVMMetrics, boolean includeBuildMetrics, boolean clearMetrics, @Nullable Map<String, String> pointTags, @Nullable MetricTranslator metricTranslator) throws IOException {
    TokenBuffer t = new TokenBuffer(new ObjectMapper(), false);
    writeJson(t, registry, includeVMMetrics, includeBuildMetrics, clearMetrics, pointTags, metricTranslator);
    JsonParser parser = t.asParser();
    return parser.readValueAsTree();
}
Also used : TokenBuffer(com.fasterxml.jackson.databind.util.TokenBuffer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 35 with JsonParser

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParser in project autorest-clientruntime-for-java by Azure.

the class FlatteningDeserializer method deserialize.

@SuppressWarnings("unchecked")
@Override
public Object deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    JsonNode root = mapper.readTree(jp);
    final Class<?> tClass = this.defaultDeserializer.handledType();
    for (Class<?> c : TypeToken.of(tClass).getTypes().classes().rawTypes()) {
        // Ignore checks for Object type.
        if (c.isAssignableFrom(Object.class)) {
            continue;
        }
        for (Field field : c.getDeclaredFields()) {
            JsonNode node = root;
            JsonProperty property = field.getAnnotation(JsonProperty.class);
            if (property != null) {
                String value = property.value();
                if (value.matches(".+[^\\\\]\\..+")) {
                    String[] values = value.split("((?<!\\\\))\\.");
                    for (String val : values) {
                        val = val.replace("\\.", ".");
                        node = node.get(val);
                        if (node == null) {
                            break;
                        }
                    }
                    ((ObjectNode) root).put(value, node);
                }
            }
        }
    }
    JsonParser parser = new JsonFactory().createParser(root.toString());
    parser.nextToken();
    return defaultDeserializer.deserialize(parser, ctxt);
}
Also used : Field(java.lang.reflect.Field) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonParser(com.fasterxml.jackson.core.JsonParser)

Aggregations

JsonParser (com.fasterxml.jackson.core.JsonParser)587 KriptonRuntimeException (com.abubusoft.kripton.exception.KriptonRuntimeException)258 JacksonWrapperParser (com.abubusoft.kripton.persistence.JacksonWrapperParser)258 KriptonJsonContext (com.abubusoft.kripton.KriptonJsonContext)257 ArrayList (java.util.ArrayList)171 IOException (java.io.IOException)126 JsonFactory (com.fasterxml.jackson.core.JsonFactory)76 Test (org.junit.Test)57 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)51 JsonNode (com.fasterxml.jackson.databind.JsonNode)46 HashSet (java.util.HashSet)43 JsonToken (com.fasterxml.jackson.core.JsonToken)41 LinkedHashSet (java.util.LinkedHashSet)38 HashMap (java.util.HashMap)35 LinkedList (java.util.LinkedList)26 JsonParseException (com.fasterxml.jackson.core.JsonParseException)23 JsonUtil.createJsonParser (com.facebook.presto.util.JsonUtil.createJsonParser)21 List (java.util.List)21 DeserializationContext (com.fasterxml.jackson.databind.DeserializationContext)20 InputStream (java.io.InputStream)20