List of usage examples for com.fasterxml.jackson.core JsonParser getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:org.mongojack.internal.DBRefDeserializer.java
@Override public DBRef deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { // First of all, make sure that we can get a copy of the DBCollection if (jp instanceof JacksonDBCollectionProvider) { K id = null;//from w ww .j a va 2 s . c o m String collectionName = null; JsonToken token = jp.getCurrentToken(); if (token == JsonToken.VALUE_NULL) { return null; } if (token == JsonToken.VALUE_EMBEDDED_OBJECT) { // Someones already kindly decoded it for us Object object = jp.getEmbeddedObject(); if (object instanceof com.mongodb.DBRef) { if (keyDeserializer != null) { id = keyDeserializer.deserialize(jp, ctxt); } else { id = (K) ((com.mongodb.DBRef) object).getId(); } collectionName = ((com.mongodb.DBRef) object).getRef(); } else { throw ctxt.instantiationException(DBRef.class, "Don't know what to do with embedded object: " + object); } } else if (token == JsonToken.START_OBJECT) { token = jp.nextValue(); while (token != JsonToken.END_OBJECT) { if (jp.getCurrentName().equals("$id")) { if (keyDeserializer != null) { id = keyDeserializer.deserialize(jp, ctxt); } else { id = (K) jp.getEmbeddedObject(); } } else if (jp.getCurrentName().equals("$ref")) { collectionName = jp.getText(); } else { // Ignore the rest } token = jp.nextValue(); } } if (id == null) { return null; } if (collectionName == null) { throw ctxt.instantiationException(DBRef.class, "DBRef contains no collection name"); } JacksonDBCollection coll = ((JacksonDBCollectionProvider) jp).getDBCollection(); JacksonDBCollection<T, K> refColl = coll.getReferenceCollection(collectionName, type, keyType); return new FetchableDBRef<T, K>(id, refColl); } else { throw ctxt.instantiationException(DBRef.class, "DBRef can only be deserialised by this deserializer if parser implements " + JacksonDBCollectionProvider.class.getName() + " parser is actually " + jp.getClass().getName()); } }