com.fasterxml.jackson.core.JsonParser.NumberType Java Examples
The following examples show how to use
com.fasterxml.jackson.core.JsonParser.NumberType.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReadTreeSequencesTest.java From jackson-jr with Apache License 2.0 | 6 votes |
private void _verifyTreeSequence(ValueIterator<JrsValue> it) throws Exception { assertTrue(it.hasNext()); JrsValue tree = it.nextValue(); assertTrue(tree.isObject()); assertEquals(2, tree.size()); assertEquals(NumberType.INT, tree.path("id").numberType()); assertEquals("foo", tree.path("msg").asText()); assertTrue(it.hasNext()); tree = it.nextValue(); assertTrue(tree.isArray()); assertEquals(3, tree.size()); assertTrue(tree.get(0).isNumber()); assertTrue(tree.get(1).isNumber()); assertEquals(NumberType.INT, tree.get(2).numberType()); assertTrue(it.hasNext()); tree = it.nextValue(); assertTrue(tree.isNull()); assertFalse(it.hasNext()); }
Example #2
Source File: StdSerializer.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Helper method that calls necessary visit method(s) to indicate that the * underlying JSON type is JSON Integer number. * * @since 2.7 */ protected void visitIntFormat(JsonFormatVisitorWrapper visitor, JavaType typeHint, NumberType numberType) throws JsonMappingException { JsonIntegerFormatVisitor v2 = visitor.expectIntegerFormat(typeHint); if (_neitherNull(v2, numberType)) { v2.numberType(numberType); } }
Example #3
Source File: StdSerializer.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Helper method that calls necessary visit method(s) to indicate that the * underlying JSON type is JSON Integer number, but that there is also a further * format restriction involved. * * @since 2.7 */ protected void visitIntFormat(JsonFormatVisitorWrapper visitor, JavaType typeHint, NumberType numberType, JsonValueFormat format) throws JsonMappingException { JsonIntegerFormatVisitor v2 = visitor.expectIntegerFormat(typeHint); if (v2 != null) { if (numberType != null) { v2.numberType(numberType); } if (format != null) { v2.format(format); } } }
Example #4
Source File: StdSerializer.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Helper method that calls necessary visit method(s) to indicate that the * underlying JSON type is a floating-point JSON number. * * @since 2.7 */ protected void visitFloatFormat(JsonFormatVisitorWrapper visitor, JavaType typeHint, NumberType numberType) throws JsonMappingException { JsonNumberFormatVisitor v2 = visitor.expectNumberFormat(typeHint); if (v2 != null) { v2.numberType(numberType); } }
Example #5
Source File: OptimizedSettableBeanProperty.java From jackson-modules-base with Apache License 2.0 | 5 votes |
protected final boolean _deserializeBooleanFromOther(JsonParser p, DeserializationContext ctxt) throws IOException { if (p.getNumberType() == NumberType.LONG) { return (p.getLongValue() == 0L) ? Boolean.FALSE : Boolean.TRUE; } // no really good logic; let's actually resort to textual comparison String str = p.getText(); if ("0.0".equals(str) || "0".equals(str)) { return Boolean.FALSE; } return Boolean.TRUE; }
Example #6
Source File: DeserializeJSONJackson.java From openbd-core with GNU General Public License v3.0 | 5 votes |
private cfData parseArray(JsonParser jp, cfArrayData array, boolean bStrictMapping ) throws JsonParseException, IOException, cfmRunTimeException{ JsonToken token = jp.nextToken(); while ( token != JsonToken.END_ARRAY ){ if ( token == JsonToken.START_ARRAY ){ array.addElement( parseArray(jp,cfArrayData.createArray(1),bStrictMapping ) ); }else if ( token == JsonToken.START_OBJECT ){ array.addElement( parseObject(jp,new cfStructData(),bStrictMapping) ); }else if ( token == JsonToken.VALUE_NUMBER_INT ){ if ( jp.getNumberType() == NumberType.INT ) array.addElement( new cfNumberData(jp.getIntValue()) ); else if ( jp.getNumberType() == NumberType.LONG || jp.getNumberType() == NumberType.BIG_INTEGER ) array.addElement( new cfNumberData(jp.getLongValue()) ); }else if ( token == JsonToken.VALUE_NUMBER_FLOAT ){ if ( jp.getNumberType() == NumberType.FLOAT ) array.addElement( new cfNumberData(jp.getFloatValue()) ); else if ( jp.getNumberType() == NumberType.DOUBLE ) array.addElement( new cfNumberData(jp.getDoubleValue()) ); } else if ( token == JsonToken.VALUE_FALSE ){ array.addElement( cfBooleanData.FALSE ); } else if ( token == JsonToken.VALUE_TRUE ){ array.addElement( cfBooleanData.TRUE ); } else if ( token == JsonToken.VALUE_NULL ){ array.addElement( cfNullData.NULL ); }else array.addElement( getString(jp.getText()) ); token = jp.nextToken(); } return array; }
Example #7
Source File: BooleanSerializer.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException { // 27-Mar-2017, tatu: As usual, bit tricky but... seems like we should call // visitor for actual representation visitIntFormat(visitor, typeHint, NumberType.INT); }
Example #8
Source File: OptimizedSettableBeanProperty.java From jackson-modules-base with Apache License 2.0 | 4 votes |
protected final boolean _deserializeBoolean(JsonParser p, DeserializationContext ctxt) throws IOException { JsonToken t = p.currentToken(); if (t == JsonToken.VALUE_TRUE) return true; if (t == JsonToken.VALUE_FALSE) return false; if (t == JsonToken.VALUE_NULL) { if (ctxt.isEnabled(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES)) { _failNullToPrimitiveCoercion(ctxt, "boolean"); } return false; } if (t == JsonToken.VALUE_NUMBER_INT) { _verifyScalarCoercion(ctxt, p, "boolean"); // 11-Jan-2012, tatus: May be outside of int... if (p.getNumberType() == NumberType.INT) { return (p.getIntValue() != 0); } return _deserializeBooleanFromOther(p, ctxt); } // And finally, let's allow Strings to be converted too if (t == JsonToken.VALUE_STRING) { _verifyScalarCoercion(ctxt, p, "boolean"); String text = p.getText().trim(); if ("true".equals(text) || "True".equals(text)) { return true; } if ("false".equals(text) || "False".equals(text) || text.length() == 0) { return false; } if (_hasTextualNull(text)) { return false; } throw ctxt.weirdStringException(text, Boolean.TYPE, "only \"true\" or \"false\" recognized"); } // [databind#381] if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) { p.nextToken(); final boolean parsed = _deserializeBooleanFromOther(p, ctxt); t = p.nextToken(); if (t != JsonToken.END_ARRAY) { _handleMissingEndArrayForSingle(p, ctxt); } return parsed; } // Otherwise, no can do: return (Boolean) ctxt.handleUnexpectedToken(getType(), p); }
Example #9
Source File: DeserializeJSONJackson.java From openbd-core with GNU General Public License v3.0 | 4 votes |
private cfData parseObject(JsonParser jp, cfStructData struct, boolean bStrictMapping ) throws JsonParseException, IOException, cfmRunTimeException{ JsonToken token = jp.nextToken(); while ( token != JsonToken.END_OBJECT ){ String namefield = jp.getCurrentName(); if ( token == JsonToken.START_ARRAY ){ struct.setData( namefield, parseArray(jp, cfArrayData.createArray(1), bStrictMapping) ); }else if ( token == JsonToken.START_OBJECT ){ struct.setData( namefield, parseObject(jp,new cfStructData(), bStrictMapping) ); }else if ( token == JsonToken.VALUE_NUMBER_INT ){ if ( jp.getNumberType() == NumberType.INT ) struct.setData( namefield, new cfNumberData(jp.getIntValue()) ); else if ( jp.getNumberType() == NumberType.LONG || jp.getNumberType() == NumberType.BIG_INTEGER ) struct.setData( namefield, new cfNumberData(jp.getLongValue()) ); }else if ( token == JsonToken.VALUE_NUMBER_FLOAT ){ if ( jp.getNumberType() == NumberType.FLOAT ) struct.setData( namefield, new cfNumberData(jp.getFloatValue()) ); else if ( jp.getNumberType() == NumberType.DOUBLE ) struct.setData( namefield, new cfNumberData(jp.getDoubleValue()) ); } else if ( token == JsonToken.VALUE_FALSE ){ struct.setData( namefield, cfBooleanData.FALSE ); } else if ( token == JsonToken.VALUE_TRUE ){ struct.setData( namefield, cfBooleanData.TRUE ); } else if ( token == JsonToken.VALUE_NULL ){ struct.setData( namefield, cfNullData.NULL ); }else{ struct.setData( namefield, getString(jp.getText()) ); } token = jp.nextToken(); } if ( bStrictMapping ) return convertToQuery( struct ); else return struct; }
Example #10
Source File: TreeApiTest.java From jackson-jr with Apache License 2.0 | 4 votes |
@Override public NumberType numberType() { return null; }