Java Jackson如何决定从数值创建什么类型的NumericNode
在我的Java Jackson如何决定从数值创建什么类型的NumericNode,java,json,jackson,jackson-databind,jackson-dataformat-xml,Java,Json,Jackson,Jackson Databind,Jackson Dataformat Xml,在我的JSON字符串中,我有一个名为price的键,当我使用mapper.readTree(string)从JSON字符串构建JsonNode时,price的数值被转换为NumericNode。有时它是一个DoubleNode或FloatNode或IntNode等。我知道它根据数据类型创建适当的节点,但是否有任何特定的节点创建顺序。例如:尝试创建IntNode,如果失败,则尝试创建LongNode JSON字符串:- { "price":1, "price1":1234, "pric
JSON
字符串中,我有一个名为price
的键,当我使用mapper.readTree(string)
从JSON
字符串构建JsonNode
时,price的数值被转换为NumericNode
。有时它是一个DoubleNode
或FloatNode
或IntNode
等。我知道它根据数据类型创建适当的节点,但是否有任何特定的节点创建顺序。例如:尝试创建IntNode
,如果失败,则尝试创建LongNode
JSON字符串:-
{
"price":1,
"price1":1234,
"price2":2224322343,
"price3":123.43,
"price4":1231231212.43
}
收到一个请求:
JsonTokenId.ID\u NUMBER\u INT`的节点JSONNodeDrializer.deserializeObject(JsonParser、DeserializationContext、JsonNodeFactory)可以看到类型为
- 后者调用
,后者调用\u fromInt()
ParserBase.getNumberType()
- 后者调用
,它根据组成值的字符数决定使用哪种类型:\u parseNumericValue()
if (_currToken == JsonToken.VALUE_NUMBER_INT) { int len = _intLength; // First: optimization for simple int if (len <= 9) { int i = _textBuffer.contentsAsInt(_numberNegative); _numberInt = i; _numTypesValid = NR_INT; return; } if (len <= 18) { // definitely fits AND is easy to parse using 2 int parse calls long l = _textBuffer.contentsAsLong(_numberNegative); // Might still fit in int, need to check if (len == 10) { if (_numberNegative) { if (l >= MIN_INT_L) { _numberInt = (int) l; _numTypesValid = NR_INT; return; } } else { if (l <= MAX_INT_L) { _numberInt = (int) l; _numTypesValid = NR_INT; return; } } } _numberLong = l; _numTypesValid = NR_LONG; return; } _parseSlowInt(expType); return; }
if(\u currToken==JsonToken.VALUE\u NUMBER\u INT){ int len=_intLength; //第一:简单整数的优化 如果(len有请求进来:
JsonTokenId.ID\u NUMBER\u INT`的节点JSONNodeDrializer.deserializeObject(JsonParser、DeserializationContext、JsonNodeFactory)可以看到类型为
- 后者调用
,后者调用\u fromInt()
ParserBase.getNumberType()
- 后者调用
,它根据组成值的字符数决定使用哪种类型:\u parseNumericValue()
if (_currToken == JsonToken.VALUE_NUMBER_INT) { int len = _intLength; // First: optimization for simple int if (len <= 9) { int i = _textBuffer.contentsAsInt(_numberNegative); _numberInt = i; _numTypesValid = NR_INT; return; } if (len <= 18) { // definitely fits AND is easy to parse using 2 int parse calls long l = _textBuffer.contentsAsLong(_numberNegative); // Might still fit in int, need to check if (len == 10) { if (_numberNegative) { if (l >= MIN_INT_L) { _numberInt = (int) l; _numTypesValid = NR_INT; return; } } else { if (l <= MAX_INT_L) { _numberInt = (int) l; _numTypesValid = NR_INT; return; } } } _numberLong = l; _numTypesValid = NR_LONG; return; } _parseSlowInt(expType); return; }
if(\u currToken==JsonToken.VALUE\u NUMBER\u INT){ int len=_intLength; //第一:简单整数的优化 如果(len)