use of com.fasterxml.jackson.core.JsonToken in project spring-security-oauth by spring-projects.
the class Jackson2ArrayOrStringDeserializer method deserialize.
@Override
public Set<String> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
JsonToken token = jp.getCurrentToken();
if (token.isScalarValue()) {
String list = jp.getText();
list = list.replaceAll("\\s+", ",");
return new LinkedHashSet<String>(Arrays.asList(StringUtils.commaDelimitedListToStringArray(list)));
}
return jp.readValueAs(new TypeReference<Set<String>>() {
});
}
use of com.fasterxml.jackson.core.JsonToken in project drill by apache.
the class CountingJsonReader method write.
@Override
public ReadState write(BaseWriter.ComplexWriter writer) throws IOException {
try {
JsonToken token = lastSeenJsonToken;
if (token == null || token == JsonToken.END_OBJECT) {
token = parser.nextToken();
}
lastSeenJsonToken = null;
if (!parser.hasCurrentToken()) {
return ReadState.END_OF_STREAM;
} else if (token != JsonToken.START_OBJECT) {
throw new com.fasterxml.jackson.core.JsonParseException(parser, String.format("Cannot read from the middle of a record. Current token was %s ", token));
// throw new
// IllegalStateException(String.format("Cannot read from the middle of a record. Current token was %s",
// token));
}
writer.rootAsMap().bit("count").writeBit(1);
parser.skipChildren();
} catch (com.fasterxml.jackson.core.JsonParseException ex) {
if (ignoreJSONParseError()) {
if (processJSONException() == JsonExceptionProcessingState.END_OF_STREAM) {
return ReadState.JSON_RECORD_PARSE_EOF_ERROR;
} else {
return ReadState.JSON_RECORD_PARSE_ERROR;
}
} else {
throw ex;
}
}
return ReadState.WRITE_SUCCEED;
}
use of com.fasterxml.jackson.core.JsonToken in project logging-log4j2 by apache.
the class Log4jStackTraceElementDeserializer method deserialize.
@Override
public StackTraceElement deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, JsonProcessingException {
JsonToken t = jp.getCurrentToken();
// Must get an Object
if (t == JsonToken.START_OBJECT) {
String className = null, methodName = null, fileName = null;
int lineNumber = -1;
while ((t = jp.nextValue()) != JsonToken.END_OBJECT) {
final String propName = jp.getCurrentName();
if ("class".equals(propName)) {
className = jp.getText();
} else if ("file".equals(propName)) {
fileName = jp.getText();
} else if ("line".equals(propName)) {
if (t.isNumeric()) {
lineNumber = jp.getIntValue();
} else {
// An XML number always comes in a string since there is no syntax help as with JSON.
try {
lineNumber = Integer.parseInt(jp.getText().trim());
} catch (final NumberFormatException e) {
throw JsonMappingException.from(jp, "Non-numeric token (" + t + ") for property 'line'", e);
}
}
} else if ("method".equals(propName)) {
methodName = jp.getText();
} else if ("nativeMethod".equals(propName)) {
// no setter, not passed via constructor: ignore
} else {
this.handleUnknownProperty(jp, ctxt, this._valueClass, propName);
}
}
return new StackTraceElement(className, methodName, fileName, lineNumber);
}
throw ctxt.mappingException(this._valueClass, t);
}
use of com.fasterxml.jackson.core.JsonToken in project qi4j-sdk by Qi4j.
the class JacksonValueDeserializer method readMapInMap.
@Override
protected <K, V> Map<K, V> readMapInMap(JsonParser input, Function<JsonParser, K> keyDeserializer, Function<JsonParser, V> valueDeserializer, Map<K, V> map) throws Exception {
JsonToken token = input.getCurrentToken();
if (token == JsonToken.VALUE_NULL) {
return null;
}
if (token != JsonToken.START_ARRAY) {
token = input.nextToken();
}
if (token == JsonToken.VALUE_NULL) {
return null;
}
if (token != JsonToken.START_ARRAY) {
throw new ValueSerializationException("Expected an array start at " + input.getCurrentLocation().toString());
}
JsonToken currentToken = input.nextToken();
while (currentToken != JsonToken.END_ARRAY) {
if (currentToken != JsonToken.START_OBJECT) {
throw new ValueSerializationException("Expected an object start at " + input.getCurrentLocation().toString());
}
currentToken = input.nextToken();
K key = null;
V value = null;
while (currentToken != JsonToken.END_OBJECT) {
String objectKey = input.getCurrentName();
input.nextToken();
if ("key".equals(objectKey)) {
key = keyDeserializer.map(input);
} else if ("value".equals(objectKey)) {
value = valueDeserializer.map(input);
} else {
//input.nextToken();
input.skipChildren();
}
currentToken = input.nextToken();
}
if (key != null) {
map.put(key, value);
}
currentToken = input.nextToken();
}
return map;
}
use of com.fasterxml.jackson.core.JsonToken in project qi4j-sdk by Qi4j.
the class JacksonValueDeserializer method readArrayInCollection.
@Override
protected <T> Collection<T> readArrayInCollection(JsonParser input, Function<JsonParser, T> deserializer, Collection<T> collection) throws Exception {
JsonToken token = input.getCurrentToken();
if (token == JsonToken.VALUE_NULL) {
return null;
}
if (token != JsonToken.START_ARRAY) {
token = input.nextToken();
}
if (token == JsonToken.VALUE_NULL) {
return null;
}
if (token != JsonToken.START_ARRAY) {
throw new ValueSerializationException("Expected an array start at " + input.getCurrentLocation().toString());
}
while (input.nextToken() != JsonToken.END_ARRAY) {
T element = deserializer.map(input);
collection.add(element);
}
return collection;
}
Aggregations