public <T> T convertFromDocument(Document document, Class<T> entityClass) { return this.gson.fromJson(document.toJson(), entityClass); }
public <T> T convertFromDocument(Document document, Class<T> entityClass) { return this.gson.fromJson(document.toJson(), entityClass); }
protected <R extends Object> R readInternal(final DocumentDbPersistentEntity<?> entity, Class<R> type, final Document sourceDocument) { final ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); try { final DocumentDbPersistentProperty idProperty = entity.getIdProperty(); final Object idValue = sourceDocument.getId(); final JSONObject jsonObject = new JSONObject(sourceDocument.toJson()); if (idProperty != null) { // Replace the key id to the actual id field name in domain jsonObject.remove(Constants.ID_PROPERTY_NAME); jsonObject.put(idProperty.getName(), idValue); } return objectMapper.readValue(jsonObject.toString(), type); } catch (IOException e) { throw new IllegalStateException("Failed to read the source document " + sourceDocument.toJson() + " to target type " + type, e); } }
protected <R extends Object> R readInternal(final DocumentDbPersistentEntity<?> entity, Class<R> type, final Document sourceDocument) { objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); objectMapper.registerModule(provideAdvancedSerializersModule()); try { final DocumentDbPersistentProperty idProperty = entity.getIdProperty(); final Object idValue = sourceDocument.getId(); final JSONObject jsonObject = new JSONObject(sourceDocument.toJson()); if (idProperty != null) { // Replace the key id to the actual id field name in domain jsonObject.remove(Constants.ID_PROPERTY_NAME); jsonObject.put(idProperty.getName(), idValue); } return objectMapper.readValue(jsonObject.toString(), type); } catch (IOException e) { throw new IllegalStateException("Failed to read the source document " + sourceDocument.toJson() + " to target type " + type, e); } }