use of com.fasterxml.jackson.core.JsonToken in project fastjson by alibaba.
the class JacksonPageModelParser method parseSegments.
/**
* @param parser
* @throws JsonParseException
* @throws IOException
*/
private List<SegmentInstance> parseSegments(JsonParser parser) throws JsonParseException, IOException {
JsonToken current = parser.nextToken();
assertExpectedJsonToken(current, JsonToken.START_ARRAY, parser.getCurrentLocation());
List<SegmentInstance> instances = new ArrayList<SegmentInstance>();
while ((current = parser.nextToken()) != JsonToken.END_ARRAY) {
assertExpectedJsonToken(current, JsonToken.START_OBJECT, parser.getCurrentLocation());
// get pageId
String segmentId = getNextTextValue("cid", parser);
// move to field: layouts
current = parser.nextToken();
assertExpectedFiled(parser.getCurrentName(), "layouts", parser.getCurrentLocation());
SegmentInstance instance = new SegmentInstance();
instance.setLayouts(parseLayouts(parser, segmentId));
instances.add(instance);
assertExpectedJsonToken((current = parser.nextToken()), JsonToken.END_OBJECT, parser.getCurrentLocation());
}
return instances;
}
use of com.fasterxml.jackson.core.JsonToken in project pinpoint by naver.
the class FilterHintListJsonDeserializer method deserialize.
@Override
public FilterHint deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
if (!jp.getCurrentToken().isStructStart()) {
throw ctxt.mappingException(RpcHint.class, jp.getCurrentToken());
}
// skip json start
final JsonToken jsonToken = jp.nextToken();
if (jsonToken == JsonToken.END_OBJECT) {
return new FilterHint(Collections.<RpcHint>emptyList());
}
List<RpcHint> rpcHintList = new ArrayList<>();
while (true) {
final RpcHint rpcHint = jp.readValueAs(RpcHint.class);
rpcHintList.add(rpcHint);
if (jp.nextToken() == JsonToken.END_OBJECT) {
break;
}
}
return new FilterHint(rpcHintList);
}
use of com.fasterxml.jackson.core.JsonToken in project pinpoint by naver.
the class RpcHintJsonDeserializer method deserialize.
@Override
public RpcHint deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
final String applicationName = jp.getText();
if (jp.nextToken() != JsonToken.START_ARRAY) {
throw ctxt.mappingException(RpcHint.class, jp.getCurrentToken());
}
// skip start array
final JsonToken token = jp.nextToken();
// [] empty array
if (token == JsonToken.END_ARRAY) {
return new RpcHint(applicationName, Collections.<RpcType>emptyList());
}
final List<RpcType> rpcHintList = new ArrayList<>();
while (true) {
RpcType rpcType = jp.readValueAs(RpcType.class);
rpcHintList.add(rpcType);
if (jp.nextToken() == JsonToken.END_ARRAY) {
break;
}
}
return new RpcHint(applicationName, rpcHintList);
}
use of com.fasterxml.jackson.core.JsonToken in project platformlayer by platformlayer.
the class JsonMetricDataStream method accept.
@Override
public void accept(MetricDataVisitor visitor) throws IOException {
while (true) {
JsonToken token = jsonParser.nextToken();
if (token == null) {
break;
}
switch(token) {
case START_OBJECT:
visitor.startObject();
break;
case END_OBJECT:
visitor.endObject();
break;
case VALUE_STRING:
{
String s = jsonParser.getText();
visitor.gotValueString(s);
break;
}
case FIELD_NAME:
{
String key = jsonParser.getText();
visitor.gotKey(key);
break;
}
case START_ARRAY:
visitor.startArray();
break;
case END_ARRAY:
visitor.endArray();
break;
case VALUE_FALSE:
visitor.gotValueBoolean(false);
break;
case VALUE_TRUE:
visitor.gotValueBoolean(false);
break;
case VALUE_NULL:
visitor.gotValueNull();
break;
case VALUE_NUMBER_FLOAT:
case VALUE_NUMBER_INT:
{
NumberType numberType = jsonParser.getNumberType();
switch(numberType) {
case BIG_INTEGER:
case BIG_DECIMAL:
{
throw new UnsupportedOperationException("Value too large: " + jsonParser.getBigIntegerValue());
}
case INT:
{
int v = jsonParser.getIntValue();
visitor.gotValueInt(v);
break;
}
case FLOAT:
{
float v = jsonParser.getFloatValue();
visitor.gotValueFloat(v);
break;
}
case DOUBLE:
{
double v = jsonParser.getDoubleValue();
visitor.gotValueDouble(v);
break;
}
case LONG:
{
long v = jsonParser.getLongValue();
visitor.gotValueLong(v);
break;
}
default:
throw new IllegalStateException("Unexpected number type: " + numberType);
}
break;
}
case NOT_AVAILABLE:
case VALUE_EMBEDDED_OBJECT:
default:
throw new IllegalStateException("Unexpected token: " + token);
}
}
}
use of com.fasterxml.jackson.core.JsonToken in project presto by prestodb.
the class JsonFunctions method jsonArrayContains.
@SqlNullable
@ScalarFunction
@SqlType(StandardTypes.BOOLEAN)
public static Boolean jsonArrayContains(@SqlType(StandardTypes.JSON) Slice json, @SqlType(StandardTypes.BOOLEAN) boolean value) {
try (JsonParser parser = createJsonParser(JSON_FACTORY, json)) {
if (parser.nextToken() != START_ARRAY) {
return null;
}
while (true) {
JsonToken token = parser.nextToken();
if (token == null) {
return null;
}
if (token == END_ARRAY) {
return false;
}
parser.skipChildren();
if (((token == VALUE_TRUE) && value) || ((token == VALUE_FALSE) && (!value))) {
return true;
}
}
} catch (IOException e) {
return null;
}
}
Aggregations