当前位置: 首页>>代码示例>>Java>>正文


Java JsonToken.VALUE_NULL属性代码示例

本文整理汇总了Java中com.fasterxml.jackson.core.JsonToken.VALUE_NULL属性的典型用法代码示例。如果您正苦于以下问题:Java JsonToken.VALUE_NULL属性的具体用法?Java JsonToken.VALUE_NULL怎么用?Java JsonToken.VALUE_NULL使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在com.fasterxml.jackson.core.JsonToken的用法示例。


在下文中一共展示了JsonToken.VALUE_NULL属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: unmarshall

public Map<K, V> unmarshall(JsonUnmarshallerContext context) throws Exception {
    Map<K, V> map = new HashMap<K, V>();
    int originalDepth = context.getCurrentDepth();

    if (context.getCurrentToken() == JsonToken.VALUE_NULL) {
        return null;
    }

    while (true) {
        JsonToken token = context.nextToken();
        if (token == null) return map;

        if (token == FIELD_NAME) {
            K k = keyUnmarshaller.unmarshall(context);
            token = context.nextToken();
            V v = valueUnmarshaller.unmarshall(context);
            map.put(k, v);
        } else if (token == END_ARRAY || token == END_OBJECT) {
            if (context.getCurrentDepth() <= originalDepth) return map;
        }
    }
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:22,代码来源:MapUnmarshaller.java

示例2: unmarshallJsonToList

/**
 * Unmarshalls the current token in the Json document to list.
 */
private List<T> unmarshallJsonToList(JsonUnmarshallerContext context)
        throws Exception {
    List<T> list = new ArrayList<T>();

    if (context.getCurrentToken() == JsonToken.VALUE_NULL) {
        return null;
    }

    while (true) {
        JsonToken token = context.nextToken();
        if (token == null) {
            return list;
        }

        if (token == END_ARRAY) {
            return list;
        } else {
            list.add(itemUnmarshaller.unmarshall(context));
        }
    }
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:24,代码来源:ListUnmarshaller.java

示例3: deserialize

@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
  Object result = createResult();
  for (String fieldName = p.nextFieldName(); fieldName != null; fieldName = p.nextFieldName()) {
    // p实际是ProtobufParser,其内部是可以直接取到proto field的,理论上可以根据id来索引
    // 可是field默认没暴露出来,所以,直接用name索引了
    ReaderHelpData helpData = readerHelpDataMap.get(fieldName);
    if (helpData == null) {
      continue;
    }

    JsonToken t = p.nextToken();
    // Note: must handle null explicitly here; value deserializers won't
    Object value = null;
    if (t == JsonToken.VALUE_NULL) {
      value = helpData.getDeser().getNullValue(ctxt);
    } else {
      value = helpData.getDeser().deserialize(p, ctxt);
    }

    result = updateResult(result, value, helpData);
  }

  return result;
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:25,代码来源:AbstractDeserializer.java

示例4: unmarshall

public Map<K, V> unmarshall(JsonUnmarshallerContext context) throws Exception {
    Map<K, V> map = new HashMap<K, V>();
    int originalDepth = context.getCurrentDepth();

    if (context.getCurrentToken() == JsonToken.VALUE_NULL) {
        return null;
    }

    while (true) {
        JsonToken token = context.nextToken();
        if (token == null) {
            return map;
        }

        if (token == FIELD_NAME) {
            K k = keyUnmarshaller.unmarshall(context);
            context.nextToken();
            V v = valueUnmarshaller.unmarshall(context);
            map.put(k, v);
        } else if (token == END_ARRAY || token == END_OBJECT) {
            if (context.getCurrentDepth() <= originalDepth) {
                return map;
            }
        }
    }
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:26,代码来源:MapUnmarshaller.java

示例5: objectBytes

@Override
public Object objectBytes() throws IOException {
    JsonToken currentToken = parser.getCurrentToken();
    if (currentToken == JsonToken.VALUE_STRING) {
        return utf8Bytes();
    } else if (currentToken == JsonToken.VALUE_NUMBER_INT || currentToken == JsonToken.VALUE_NUMBER_FLOAT) {
        return parser.getNumberValue();
    } else if (currentToken == JsonToken.VALUE_TRUE) {
        return Boolean.TRUE;
    } else if (currentToken == JsonToken.VALUE_FALSE) {
        return Boolean.FALSE;
    } else if (currentToken == JsonToken.VALUE_NULL) {
        return null;
    } else {
        //TODO should this really do UTF-8 conversion?
        return utf8Bytes();
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:18,代码来源:JsonXContentParser.java

示例6: doMerge

@Override
public void doMerge(JsonParser parser, int currentDepth, Message.Builder messageBuilder)
    throws IOException {
  Value.Builder builder = (Value.Builder) messageBuilder;
  JsonToken token = parser.currentToken();
  if (token.isBoolean()) {
    builder.setBoolValue(ParseSupport.parseBool(parser));
  } else if (token.isNumeric()) {
    builder.setNumberValue(ParseSupport.parseDouble(parser));
  } else if (token == JsonToken.VALUE_NULL) {
    builder.setNullValue(NullValue.NULL_VALUE);
  } else if (token.isScalarValue()) {
    builder.setStringValue(ParseSupport.parseString(parser));
  } else if (token == JsonToken.START_OBJECT) {
    Struct.Builder structBuilder = builder.getStructValueBuilder();
    StructMarshaller.INSTANCE.mergeValue(parser, currentDepth + 1, structBuilder);
  } else if (token == JsonToken.START_ARRAY) {
    ListValue.Builder listValueBuilder = builder.getListValueBuilder();
    ListValueMarshaller.INSTANCE.mergeValue(parser, currentDepth + 1, listValueBuilder);
  } else {
    throw new IllegalStateException("Unexpected json data: " + parser.getText());
  }
}
 
开发者ID:curioswitch,项目名称:curiostack,代码行数:23,代码来源:WellKnownTypeMarshaller.java

示例7: jsonToColumnValue

@Override
public Value jsonToColumnValue(final JsonParser parser, final ValueMetadata metadata) throws IOException {

    JsonToken token;
    Value value;

    // Go to the next token
    token = parser.nextToken();

    if (token != JsonToken.VALUE_NUMBER_INT && token != JsonToken.VALUE_NULL) {
        throw new IOException("Unable to parse field " + metadata.getName() + " expected int or null at line " + parser.getCurrentLocation().getLineNr());
    }

    // Can be a integer or null
    if (token == JsonToken.VALUE_NUMBER_INT) {
        value = new Value(parser.getValueAsLong(), metadata);
    } else {
        // null
        if (metadata.isNotNull()) {
            throw new IOException("Unable to parse field " + metadata.getName() + " expected int bu found null at line " + parser.getCurrentLocation().getLineNr());
        }

        value = new Value(metadata);
    }

    return value;
}
 
开发者ID:claudiodegio,项目名称:dbsync,代码行数:27,代码来源:JSonLongConverter.java

示例8: parseField

@Override
public void parseField(PrivateFieldModel instance, String fieldName, JsonParser jsonParser) throws IOException {
    if ("string_to_test_m_vars".equals(fieldName)) {
        instance.setStringThatStartsWithM(jsonParser.getValueAsString(null));
    } else if ("privateBoolean".equals(fieldName)){
        instance.setPrivateBoolean(jsonParser.getValueAsBoolean());
    } else if ("privateList".equals(fieldName)){
        if (jsonParser.getCurrentToken() == JsonToken.START_ARRAY) {
            ArrayList<String> collection1 = new ArrayList<String>();
            while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                String value1;
                value1 = jsonParser.getValueAsString(null);
                collection1.add(value1);
            }
            instance.setPrivateList(collection1);
        } else {
            instance.setPrivateList(null);
        }
    } else if ("privateMap".equals(fieldName)){
        if (jsonParser.getCurrentToken() == JsonToken.START_OBJECT) {
            HashMap<String, String> map1 = new HashMap<String, String>();
            while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
                String key1 = jsonParser.getText();
                jsonParser.nextToken();
                if (jsonParser.getCurrentToken() == JsonToken.VALUE_NULL) {
                    map1.put(key1, null);
                } else{
                    map1.put(key1, jsonParser.getValueAsString(null));
                }
            }
            instance.setPrivateMap(map1);
        } else {
            instance.setPrivateMap(null);
        }
    } else if ("private_named_string".equals(fieldName)){
        instance.setPrivateNamedString(jsonParser.getValueAsString(null));
    } else if ("privateString".equals(fieldName)){
        instance.setPrivateString(jsonParser.getValueAsString(null));
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:40,代码来源:PrivateFieldModel$$JsonObjectMapper.java

示例9: parseMap

/**
 * Parse a map of objects from a JsonParser.
 *
 * @param jsonParser The JsonParser, preconfigured to be at the START_ARRAY token.
 */
public Map<String, T> parseMap(JsonParser jsonParser) throws IOException {
    HashMap<String, T> map = new HashMap<String, T>();
    while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
        String key = jsonParser.getText();
        jsonParser.nextToken();
        if (jsonParser.getCurrentToken() == JsonToken.VALUE_NULL) {
            map.put(key, null);
        } else{
            map.put(key, parse(jsonParser));
        }
    }
    return map;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:JsonMapper.java

示例10: parse

@Override
public Integer parse(JsonParser jsonParser) throws IOException {
    if (jsonParser.getCurrentToken() == JsonToken.VALUE_NULL) {
        return null;
    } else {
        return jsonParser.getIntValue();
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:8,代码来源:IntegerMapper.java

示例11: getValueAsString

@Override
public String getValueAsString(String defaultValue) throws IOException {
    // The documentation is ambiguous about whether field names should
    // return their text or the default value. To conform with the
    // CBORParser, they will get the default value here.
    if (currentToken != JsonToken.VALUE_STRING) {
        if (currentToken == null || currentToken == JsonToken.VALUE_NULL || !currentToken.isScalarValue()) {
            return defaultValue;
        }
    }
    return getText();
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:12,代码来源:IonParser.java

示例12: readNextTokenAsInt

private Integer readNextTokenAsInt() throws IOException {
    if (mJp.nextToken() != JsonToken.VALUE_NUMBER_INT) {
        if (mJp.getCurrentToken() == JsonToken.VALUE_NULL) {
            throw new IOException("Unable to parse token as NUMBER_INT is null line:" + mJp.getCurrentLocation().getLineNr());
        } else {
            throw new IOException("Unable to parse token as NUMBER_INT line:" + mJp.getCurrentLocation().getLineNr());
        }
    }
    return mJp.getIntValue();
}
 
开发者ID:claudiodegio,项目名称:dbsync,代码行数:10,代码来源:JSonDatabaseReader.java

示例13: parse

@Override
public Boolean parse(JsonParser jsonParser) throws IOException {
    if (jsonParser.getCurrentToken() == JsonToken.VALUE_NULL) {
        return null;
    } else {
        return jsonParser.getBooleanValue();
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:8,代码来源:BooleanMapper.java

示例14: checkToken

public boolean checkToken(final JsonToken t, final JsonToken expected1, final JsonToken expected2) throws IOException{
  if(t == JsonToken.VALUE_NULL){
    return true;
  }else if(t == expected1){
    return false;
  }else if(t == expected2){
    return false;
  }else{
    throw new JsonParseException(String.format("Failure while reading ExtendedJSON typed value. Expected a %s but "
        + "received a token of type %s", expected1, t), parser.getCurrentLocation());
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:12,代码来源:VectorOutput.java

示例15: deserialize

@Override
public Nullable<Object> deserialize(JsonParser jp, DeserializationContext context) throws IOException {
	JsonToken currentToken = jp.getCurrentToken();
	if (currentToken == JsonToken.START_ARRAY) {
		Resource[] resources = jp.readValueAs(Resource[].class);
		return Nullable.of((Object) Arrays.asList(resources));
	}
	else if (currentToken == JsonToken.VALUE_NULL) {
		return Nullable.nullValue();
	}
	else {
		PreconditionUtil.assertEquals("parsing failed", currentToken, JsonToken.START_OBJECT);
		return Nullable.of((Object) jp.readValueAs(Resource.class));
	}
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:15,代码来源:DocumentDataDeserializer.java


注:本文中的com.fasterxml.jackson.core.JsonToken.VALUE_NULL属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。