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;
}
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));
});
}
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);
}
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();
}
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);
}
Aggregations