/** * Creates a new ObjectReader with this Genson instance configuration. */ public ObjectReader createReader(InputStream is, Charset charset) { return createReader(new InputStreamReader(is, charset)); }
/** * @see #deserializeInto(com.owlike.genson.stream.ObjectReader, Object, Context) */ public <T> T deserializeInto(String json, T object) { return deserializeInto(createReader(new StringReader(json)), object, new Context(this)); }
/** * @see #deserializeInto(com.owlike.genson.stream.ObjectReader, Object, Context) */ public <T> T deserializeInto(String json, T object) { return deserializeInto(createReader(new StringReader(json)), object, new Context(this)); }
InputStream instream = entity.getContent(); Genson genson = new Genson(); ObjectReader reader = genson.createReader(instream); DeserializeIntoThisClass myObject = genson.deserialize(DeserializeIntoThisClass.class, reader, new Context(genson)); // and now you can work with this object and store it in a database if you want
/** * Deserializes to an instance of T. GenericType is useful when you want to deserialize to a * list or map (or any other type with generics). * * @param fromSource * @param toType * @throws com.owlike.genson.JsonBindingException * @throws JsonStreamException * @see GenericType */ public <T> T deserialize(String fromSource, GenericType<T> toType) { return deserialize(toType, createReader(new StringReader(fromSource)), new Context(this)); }
/** * Deserializes the incoming json stream into an instance of T. * Genson did not create the instance of Reader so it will not be closed */ public <T> T deserialize(Reader reader, GenericType<T> toType) { return deserialize(toType, createReader(reader), new Context(this)); }
/** * Deserializes the incoming json stream into an instance of T. * Genson did not create the instance of InputStream so it will not be closed. */ public <T> T deserialize(InputStream input, GenericType<T> toType) { return deserialize(toType, createReader(input), new Context(this)); }
public <T> T deserialize(String fromSource, Class<T> toType, Class<? extends BeanView<?>>... withViews) { StringReader reader = new StringReader(fromSource); return deserialize(GenericType.of(toType), createReader(reader), new Context(this, Arrays.asList(withViews))); }
/** * @see #deserializeInto(com.owlike.genson.stream.ObjectReader, Object, Context) */ public <T> T deserializeInto(byte[] jsonBytes, T object) { return deserializeInto(createReader(jsonBytes), object, new Context(this)); }
/** * Deserializes the incoming json byte array into an instance of T. */ public <T> T deserialize(byte[] input, GenericType<T> toType) { return deserialize(toType, createReader(input), new Context(this)); }
/** * @see #deserializeValues(com.owlike.genson.stream.ObjectReader, GenericType) */ public <T> Iterator<T> deserializeValues(final InputStream is, final Class<T> type) { return deserializeValues(createReader(is), GenericType.of(type)); }
/** * Deserializes the incoming json stream into an instance of T. * Genson did not create the instance of Reader so it will not be closed */ public <T> T deserialize(Reader reader, GenericType<T> toType) { return deserialize(toType, createReader(reader), new Context(this)); }
/** * Deserializes the incoming json stream into an instance of T. * Genson did not create the instance of InputStream so it will not be closed. */ public <T> T deserialize(InputStream input, GenericType<T> toType) { return deserialize(toType, createReader(input), new Context(this)); }
/** * Creates a new ObjectReader with this Genson instance configuration and tries to detect the encoding * from the stream content. */ public ObjectReader createReader(InputStream is) { try { return createReader(readerFactory.createReader(is)); } catch (IOException e) { throw new JsonStreamException("Failed to detect encoding.", e); } }
/** * @see #deserializeValues(com.owlike.genson.stream.ObjectReader, GenericType) */ public <T> Iterator<T> deserializeValues(final InputStream is, final Class<T> type) { return deserializeValues(createReader(is), GenericType.of(type)); }
/** * @see #deserializeInto(com.owlike.genson.stream.ObjectReader, Object, Context) */ public <T> T deserializeInto(byte[] jsonBytes, T object) { return deserializeInto(createReader(jsonBytes), object, new Context(this)); }
/** * @see #deserializeInto(com.owlike.genson.stream.ObjectReader, Object, Context) */ public <T> T deserializeInto(InputStream is, T object) { return deserializeInto(createReader(is), object, new Context(this)); }
/** * Deserializes fromSource String into an instance of toClass. * * @param fromSource source from which to deserialize. * @param toClass type into which to deserialize. * @throws com.owlike.genson.JsonBindingException * @throws JsonStreamException */ public <T> T deserialize(String fromSource, Class<T> toClass) { return deserialize(GenericType.of(toClass), createReader(new StringReader(fromSource)), new Context(this)); }
/** * Deserializes the incoming json stream into an instance of T. * Genson did not create the instance of Reader so it will not be closed */ public <T> T deserialize(Reader reader, Class<T> toType) { return deserialize(GenericType.of(toType), createReader(reader), new Context(this)); }
@Benchmark @Override public Object genson() throws Exception { try (ObjectReader reader = JSON_SOURCE().provider().genson().createReader(JSON_SOURCE().nextByteArray())) { return JSON_SOURCE().streamDeserializer().genson(reader); } }