Java Code Examples for com.fasterxml.jackson.core.JsonToken#VALUE_EMBEDDED_OBJECT
The following examples show how to use
com.fasterxml.jackson.core.JsonToken#VALUE_EMBEDDED_OBJECT .
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: ArrowRecordBatchSerDe.java From aws-athena-query-federation with Apache License 2.0 | 6 votes |
@Override protected ArrowRecordBatch doDeserialize(JsonParser jparser, DeserializationContext ctxt) throws IOException { if (jparser.nextToken() != JsonToken.VALUE_EMBEDDED_OBJECT) { throw new IllegalStateException("Expecting " + JsonToken.VALUE_STRING + " but found " + jparser.getCurrentLocation()); } byte[] bytes = jparser.getBinaryValue(); AtomicReference<ArrowRecordBatch> batch = new AtomicReference<>(); try { return blockAllocator.registerBatch((BufferAllocator root) -> { batch.set((ArrowRecordBatch) MessageSerializer.deserializeMessageBatch( new ReadChannel(Channels.newChannel(new ByteArrayInputStream(bytes))), root)); return batch.get(); }); } catch (Exception ex) { if (batch.get() != null) { batch.get().close(); } throw ex; } }
Example 2
Source File: ZonedDateTimeDeserializer.java From mongo-jackson-codec with Apache License 2.0 | 6 votes |
@Override public ZonedDateTime deserialize(BsonParser bsonParser, DeserializationContext ctxt) throws IOException, JsonProcessingException { if (bsonParser.getCurrentToken() != JsonToken.VALUE_EMBEDDED_OBJECT || bsonParser.getCurrentBsonType() != BsonConstants.TYPE_DATETIME) { throw ctxt.mappingException(Date.class); } Object obj = bsonParser.getEmbeddedObject(); if (obj == null) { return null; } Date dt = (Date) obj; return Instant.ofEpochMilli(dt.getTime()).atZone(ZoneId.of("UTC")); }
Example 3
Source File: OffsetDateTimeDeserializer.java From mongo-jackson-codec with Apache License 2.0 | 6 votes |
@Override public OffsetDateTime deserialize(BsonParser bsonParser, DeserializationContext ctxt) throws IOException, JsonProcessingException { if (bsonParser.getCurrentToken() != JsonToken.VALUE_EMBEDDED_OBJECT || bsonParser.getCurrentBsonType() != BsonConstants.TYPE_DATETIME) { throw ctxt.mappingException(Date.class); } Object obj = bsonParser.getEmbeddedObject(); if (obj == null) { return null; } Date dt = (Date) obj; return Instant.ofEpochMilli(dt.getTime()).atOffset(ZoneOffset.UTC); }
Example 4
Source File: InstantDeserializer.java From mongo-jackson-codec with Apache License 2.0 | 6 votes |
@Override public Instant deserialize(BsonParser bsonParser, DeserializationContext ctxt) throws IOException, JsonProcessingException { if (bsonParser.getCurrentToken() != JsonToken.VALUE_EMBEDDED_OBJECT || bsonParser.getCurrentBsonType() != BsonConstants.TYPE_DATETIME) { ctxt.mappingException(Date.class); } Object obj = bsonParser.getEmbeddedObject(); if (obj == null) { return null; } Date dt = (Date) obj; return Instant.ofEpochMilli(dt.getTime()); }
Example 5
Source File: YearDeserializer.java From jackson-modules-java8 with Apache License 2.0 | 6 votes |
@Override public Year deserialize(JsonParser parser, DeserializationContext context) throws IOException { JsonToken t = parser.currentToken(); if (t == JsonToken.VALUE_STRING) { String string = parser.getValueAsString().trim(); try { if (_formatter == null) { return Year.parse(string); } return Year.parse(string, _formatter); } catch (DateTimeException e) { return _handleDateTimeFormatException(context, e, _formatter, string); } } if (t == JsonToken.VALUE_NUMBER_INT) { return Year.of(parser.getIntValue()); } if (t == JsonToken.VALUE_EMBEDDED_OBJECT) { return (Year) parser.getEmbeddedObject(); } if (parser.hasToken(JsonToken.START_ARRAY)){ return _deserializeFromArray(parser, context); } return _handleUnexpectedToken(context, parser, JsonToken.VALUE_STRING, JsonToken.VALUE_NUMBER_INT); }
Example 6
Source File: IonParser.java From ibm-cos-sdk-java with Apache License 2.0 | 6 votes |
@Override public Object getEmbeddedObject() throws IOException { if (currentToken != JsonToken.VALUE_EMBEDDED_OBJECT) { return null; } IonType currentType = reader.getType(); switch (currentType) { case BLOB: case CLOB: return ByteBuffer.wrap(reader.newBytes()); case TIMESTAMP: return reader.timestampValue().dateValue(); default: throw new SdkClientException(String.format("Cannot return embedded object for Ion type %s", currentType)); } }
Example 7
Source File: StoredAsJsonDeserializer.java From Rosetta with Apache License 2.0 | 6 votes |
@Override public T deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { JavaType javaType = ctxt.getTypeFactory().constructType(type); ObjectMapper mapper = (ObjectMapper) jp.getCodec(); if (jp.getCurrentToken() == JsonToken.VALUE_STRING) { return deserialize(mapper, jp.getText(), javaType); } else if (jp.getCurrentToken() == JsonToken.VALUE_EMBEDDED_OBJECT) { String json = new String(jp.getBinaryValue(Base64Variants.getDefaultVariant()), StandardCharsets.UTF_8); return deserialize(mapper, json, javaType); } else if(jp.getCurrentToken() == JsonToken.START_OBJECT || jp.getCurrentToken() == JsonToken.START_ARRAY) { return mapper.readValue(jp, javaType); } else { throw ctxt.mappingException("Expected JSON String"); } }
Example 8
Source File: IonParser.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
@Override public Object getEmbeddedObject() { if (currentToken != JsonToken.VALUE_EMBEDDED_OBJECT) { return null; } IonType currentType = reader.getType(); switch (currentType) { case BLOB: case CLOB: return ByteBuffer.wrap(reader.newBytes()); case TIMESTAMP: return reader.timestampValue().dateValue(); default: throw SdkClientException.builder() .message(String.format("Cannot return embedded object for Ion type %s", currentType)) .build(); } }
Example 9
Source File: IonParser.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
private JsonToken getJsonToken() { if (reader.isNullValue()) { return JsonToken.VALUE_NULL; } IonType currentType = reader.getType(); switch (currentType) { case BLOB: case CLOB: return JsonToken.VALUE_EMBEDDED_OBJECT; case BOOL: return reader.booleanValue() ? JsonToken.VALUE_TRUE : JsonToken.VALUE_FALSE; case DECIMAL: return JsonToken.VALUE_NUMBER_FLOAT; case FLOAT: return JsonToken.VALUE_NUMBER_FLOAT; case INT: return JsonToken.VALUE_NUMBER_INT; case LIST: return JsonToken.START_ARRAY; case SEXP: return JsonToken.START_ARRAY; case STRING: return JsonToken.VALUE_STRING; case STRUCT: return JsonToken.START_OBJECT; case SYMBOL: return JsonToken.VALUE_STRING; case TIMESTAMP: return JsonToken.VALUE_EMBEDDED_OBJECT; default: throw SdkClientException.builder() .message(String.format("Unhandled Ion type %s", currentType)) .build(); } }
Example 10
Source File: CustomProtobufParser.java From caravan with Apache License 2.0 | 5 votes |
/** * Method called to finish parsing of a token so that token contents * are retriable */ @Override protected void _finishToken() throws IOException { _tokenIncomplete = false; if (_currToken == JsonToken.VALUE_STRING) { final int len = _decodedLength; if (len > _inputEnd - _inputPtr) { // or if not, could we read? if (len >= _inputBuffer.length) { // If not enough space, need different handling _finishLongText(len); return; } _loadToHaveAtLeastCtrip(len); } // offline for better optimization _finishShortText(len); return; } if (_currToken == JsonToken.VALUE_EMBEDDED_OBJECT) { _binaryValue = _finishBytes(_decodedLength); return; } // should never happen but: _throwInternal(); }
Example 11
Source File: IonParser.java From ibm-cos-sdk-java with Apache License 2.0 | 5 votes |
private JsonToken getJsonToken() { if (reader.isNullValue()) { return JsonToken.VALUE_NULL; } IonType currentType = reader.getType(); switch (currentType) { case BLOB: case CLOB: return JsonToken.VALUE_EMBEDDED_OBJECT; case BOOL: return reader.booleanValue() ? JsonToken.VALUE_TRUE : JsonToken.VALUE_FALSE; case DECIMAL: return JsonToken.VALUE_NUMBER_FLOAT; case FLOAT: return JsonToken.VALUE_NUMBER_FLOAT; case INT: return JsonToken.VALUE_NUMBER_INT; case LIST: return JsonToken.START_ARRAY; case SEXP: return JsonToken.START_ARRAY; case STRING: return JsonToken.VALUE_STRING; case STRUCT: return JsonToken.START_OBJECT; case SYMBOL: return JsonToken.VALUE_STRING; case TIMESTAMP: return JsonToken.VALUE_EMBEDDED_OBJECT; default: throw new SdkClientException(String.format("Unhandled Ion type %s", currentType)); } }
Example 12
Source File: BaseCollectionDeserializer.java From jackson-datatypes-collections with Apache License 2.0 | 5 votes |
@Override public T deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { if (p.currentToken() == JsonToken.VALUE_STRING || p.currentToken() == JsonToken.VALUE_EMBEDDED_OBJECT) { byte[] binaryValue = p.getBinaryValue(); Intermediate intermediate = createIntermediate(); intermediate.addAll(binaryValue); return finish(intermediate); } return super.deserialize(p, ctxt); }
Example 13
Source File: BaseCollectionDeserializers.java From jackson-datatypes-collections with Apache License 2.0 | 5 votes |
@Override public T deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { if (p.currentToken() == JsonToken.VALUE_STRING || p.currentToken() == JsonToken.VALUE_EMBEDDED_OBJECT) { byte[] binaryValue = p.getBinaryValue(); Intermediate intermediate = createIntermediate(binaryValue.length); intermediate.addAll(binaryValue); return finish(intermediate); } return super.deserialize(p, ctxt); }
Example 14
Source File: IdDeserializer.java From EDDI with Apache License 2.0 | 5 votes |
public String deserialize(BsonParser bsonParser, DeserializationContext ctxt) throws IOException { if (bsonParser.getCurrentToken() != JsonToken.VALUE_EMBEDDED_OBJECT || bsonParser.getCurrentBsonType() != BsonConstants.TYPE_OBJECTID) { throw ctxt.mappingException(ObjectId.class); } ObjectId parsedObjectId = (ObjectId) bsonParser.getEmbeddedObject(); int timestamp = parsedObjectId.getTime(); int machineAndProcessIdentifier = parsedObjectId.getMachine(); int counter = parsedObjectId.getInc(); byte[] bytes = new byte[12]; bytes[0] = int3(timestamp); bytes[1] = int2(timestamp); bytes[2] = int1(timestamp); bytes[3] = int0(timestamp); bytes[4] = int3(machineAndProcessIdentifier); bytes[5] = int2(machineAndProcessIdentifier); bytes[6] = int1(machineAndProcessIdentifier); bytes[7] = int0(machineAndProcessIdentifier); bytes[8] = int3(counter); bytes[9] = int2(counter); bytes[10] = int1(counter); bytes[11] = int0(counter); StringBuilder buf = new StringBuilder(24); for (final byte b : bytes) { buf.append(String.format("%02x", b & 0xff)); } return buf.toString(); }
Example 15
Source File: CustomProtobufParser.java From caravan with Apache License 2.0 | 5 votes |
@Override public Object getEmbeddedObject() throws IOException { if (_tokenIncomplete) { _finishToken(); } if (_currToken == JsonToken.VALUE_EMBEDDED_OBJECT ) { return _binaryValue; } return null; }
Example 16
Source File: CustomProtobufParser.java From caravan with Apache License 2.0 | 5 votes |
@Override public byte[] getBinaryValue(Base64Variant b64variant) throws IOException { if (_tokenIncomplete) { _finishToken(); } if (_currToken != JsonToken.VALUE_EMBEDDED_OBJECT ) { // TODO, maybe: support base64 for text? _reportError("Current token ("+_currToken+") not VALUE_EMBEDDED_OBJECT, can not access as binary"); } return _binaryValue; }
Example 17
Source File: BsonInstantDeserializer.java From clouditor with Apache License 2.0 | 5 votes |
@Override public Instant deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { // the ISODate is already parsed as a Date object in an embedded object from the BsonParser if (p.getCurrentToken() == JsonToken.VALUE_EMBEDDED_OBJECT) { return Instant.ofEpochMilli(((Date) p.getEmbeddedObject()).getTime()); } else { // otherwise, maybe somebody left a unix timestamp for us return Instant.ofEpochMilli(p.getLongValue()); } }
Example 18
Source File: JrsEmbeddedObject.java From jackson-jr with Apache License 2.0 | 4 votes |
@Override public JsonToken asToken() { return JsonToken.VALUE_EMBEDDED_OBJECT; }
Example 19
Source File: BsonParser.java From immutables with Apache License 2.0 | 4 votes |
/** * Read next token in the stream */ private JsonToken readToken() throws JsonParseException { switch (type()) { case END_OF_DOCUMENT: reader.readEndDocument(); return JsonToken.END_OBJECT; case DOCUMENT: reader.readStartDocument(); return JsonToken.START_OBJECT; case ARRAY: reader.readStartArray(); return JsonToken.START_ARRAY; case BOOLEAN: final boolean value = reader.readBoolean(); context.setValue(value); return value ? JsonToken.VALUE_TRUE : JsonToken.VALUE_FALSE; case DATE_TIME: case TIMESTAMP: return JsonToken.VALUE_EMBEDDED_OBJECT; case NULL: reader.readNull(); context.setValue(null); return JsonToken.VALUE_NULL; case SYMBOL: case STRING: return JsonToken.VALUE_STRING; case INT32: case INT64: return JsonToken.VALUE_NUMBER_INT; case DECIMAL128: case DOUBLE: return JsonToken.VALUE_NUMBER_FLOAT; case UNDEFINED: reader.readUndefined(); context.setValue(null); return JsonToken.VALUE_NULL; case OBJECT_ID: case BINARY: case REGULAR_EXPRESSION: default: return JsonToken.VALUE_EMBEDDED_OBJECT; } }
Example 20
Source File: MonthDayDeserializer.java From jackson-modules-java8 with Apache License 2.0 | 4 votes |
@Override public MonthDay deserialize(JsonParser parser, DeserializationContext context) throws IOException { if (parser.hasToken(JsonToken.VALUE_STRING)) { String string = parser.getValueAsString().trim(); try { if (_formatter == null) { return MonthDay.parse(string); } return MonthDay.parse(string, _formatter); } catch (DateTimeException e) { return _handleDateTimeFormatException(context, e, _formatter, string); } } if (parser.isExpectedStartArrayToken()) { JsonToken t = parser.nextToken(); if (t == JsonToken.END_ARRAY) { return null; } if ((t == JsonToken.VALUE_STRING || t == JsonToken.VALUE_EMBEDDED_OBJECT) && context.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) { final MonthDay parsed = deserialize(parser, context); if (parser.nextToken() != JsonToken.END_ARRAY) { handleMissingEndArrayForSingle(parser, context); } return parsed; } if (t != JsonToken.VALUE_NUMBER_INT) { _reportWrongToken(context, JsonToken.VALUE_NUMBER_INT, "month"); } int month = parser.getIntValue(); int day = parser.nextIntValue(-1); if (day == -1) { if (!parser.hasToken(JsonToken.VALUE_NUMBER_INT)) { _reportWrongToken(context, JsonToken.VALUE_NUMBER_INT, "day"); } day = parser.getIntValue(); } if (parser.nextToken() != JsonToken.END_ARRAY) { throw context.wrongTokenException(parser, handledType(), JsonToken.END_ARRAY, "Expected array to end"); } return MonthDay.of(month, day); } if (parser.hasToken(JsonToken.VALUE_EMBEDDED_OBJECT)) { return (MonthDay) parser.getEmbeddedObject(); } return _handleUnexpectedToken(context, parser, JsonToken.VALUE_STRING, JsonToken.START_ARRAY); }