當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。