Search in sources :

Example 46 with JsonToken

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);
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken)

Aggregations

JsonToken (com.fasterxml.jackson.core.JsonToken)46 JsonParser (com.fasterxml.jackson.core.JsonParser)11 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)8 SqlNullable (com.facebook.presto.spi.function.SqlNullable)7 SqlType (com.facebook.presto.spi.function.SqlType)7 JsonUtil.createJsonParser (com.facebook.presto.util.JsonUtil.createJsonParser)7 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)6 JsonParserHelper.assertExpectedJsonToken (com.alibaba.json.test.performance.JacksonPageModelParser.JsonParserHelper.assertExpectedJsonToken)5 LiteralParameters (com.facebook.presto.spi.function.LiteralParameters)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)2 RpcHint (com.navercorp.pinpoint.web.filter.RpcHint)2 InputStream (java.io.InputStream)2 ValueSerializationException (org.qi4j.api.value.ValueSerializationException)2 Company (com.alibaba.json.test.entity.Company)1 Department (com.alibaba.json.test.entity.Department)1 Employee (com.alibaba.json.test.entity.Employee)1 Group (com.alibaba.json.test.entity.Group)1 LayoutInstance (com.alibaba.json.test.entity.pagemodel.LayoutInstance)1 PageInstance (com.alibaba.json.test.entity.pagemodel.PageInstance)1