@Override public Converter<?> create(Type type, Genson genson) { Converter<?> converter = ThreadLocalHolder.get(CONTEXT_KEY, Converter.class); if (converter != null) return converter; return delegatedFactory.create(type, genson); } }
@Override public Converter<?> create(Type type, Genson genson) { Converter<?> converter = ThreadLocalHolder.get(CONTEXT_KEY, Converter.class); if (converter != null) return converter; return delegatedFactory.create(type, genson); } }
@Override public boolean shouldInclude(BeanProperty property, Context ctx) { Set<String> properties = ThreadLocalHolder.get("_jaxrs_params_to_filter", Set.class); if (inclusionFilter) return properties.contains(property.getName()); else return !properties.contains(property.getName()); }
@Override public boolean shouldInclude(BeanProperty property, Context ctx) { Set<String> properties = ThreadLocalHolder.get("_jaxrs_params_to_filter", Set.class); if (inclusionFilter) return properties.contains(property.getName()); else return !properties.contains(property.getName()); }
/** * Provides an instance of Converter capable of handling objects of type forType. * * @param forType the type for which a converter is needed. * @return the converter instance. * @throws com.owlike.genson.JsonBindingException if a problem occurs during converters lookup/construction. */ @SuppressWarnings("unchecked") public <T> Converter<T> provideConverter(Type forType) { if (Boolean.TRUE.equals(ThreadLocalHolder.get("__GENSON$DO_NOT_CACHE_CONVERTER", Boolean.class))) { return (Converter<T>) converterFactory.create(forType, this); } else { Converter<T> converter = (Converter<T>) converterCache.get(forType); if (converter == null) { converter = (Converter<T>) converterFactory.create(forType, this); if (converter == null) throw new JsonBindingException("No converter found for type " + forType); converterCache.putIfAbsent(forType, converter); } return converter; } }
/** * Provides an instance of Converter capable of handling objects of type forType. * * @param forType the type for which a converter is needed. * @return the converter instance. * @throws com.owlike.genson.JsonBindingException if a problem occurs during converters lookup/construction. */ @SuppressWarnings("unchecked") public <T> Converter<T> provideConverter(Type forType) { if (Boolean.TRUE.equals(ThreadLocalHolder.get("__GENSON$DO_NOT_CACHE_CONVERTER", Boolean.class))) { return (Converter<T>) converterFactory.create(forType, this); } else { Converter<T> converter = (Converter<T>) converterCache.get(forType); if (converter == null) { converter = (Converter<T>) converterFactory.create(forType, this); if (converter == null) throw new JsonBindingException("No converter found for type " + forType); converterCache.putIfAbsent(forType, converter); } return converter; } }
@SuppressWarnings("unchecked") @Override protected void writeInternal(Object t, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { ObjectWriter writer = genson.createWriter(outputMessage.getBody()); MethodParameter mp = ThreadLocalHolder.get("__GENSON$return_param", MethodParameter.class); WithBeanView ann = mp != null ? mp.getMethodAnnotation(WithBeanView.class) : null; if (ann != null) genson.serialize(t, writer, new Context(genson, Arrays.asList(ann.views()))); else genson.serialize(t, writer, new Context(genson)); writer.flush(); } }
@SuppressWarnings("unchecked") @Override protected void writeInternal(Object t, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { ObjectWriter writer = genson.createWriter(outputMessage.getBody()); MethodParameter mp = ThreadLocalHolder.get("__GENSON$return_param", MethodParameter.class); WithBeanView ann = mp != null ? mp.getMethodAnnotation(WithBeanView.class) : null; if (ann != null) genson.serialize(t, writer, new Context(genson, Arrays.asList(ann.views()))); else genson.serialize(t, writer, new Context(genson)); writer.flush(); } }
@Override protected Object readInternal(Class<?> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { MethodParameter mp = ThreadLocalHolder.get("__GENSON$method_param", MethodParameter.class); WithBeanView ann = null; Type type = clazz; if (mp != null) { ann = mp.getMethodAnnotation(WithBeanView.class); type = mp.getGenericParameterType(); } GenericType<?> genericType = GenericType.of(type); if (ann != null) return genson.deserialize(genericType, genson.createReader(inputMessage.getBody()), new Context(genson, Arrays.asList(ann.views()))); else return genson.deserialize(genericType, genson.createReader(inputMessage.getBody()), new Context(genson)); }
@Override protected Object readInternal(Class<?> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { MethodParameter mp = ThreadLocalHolder.get("__GENSON$method_param", MethodParameter.class); WithBeanView ann = null; Type type = clazz; if (mp != null) { ann = mp.getMethodAnnotation(WithBeanView.class); type = mp.getGenericParameterType(); } GenericType<?> genericType = GenericType.of(type); if (ann != null) return genson.deserialize(genericType, genson.createReader(inputMessage.getBody()), new Context(genson, Arrays.asList(ann.views()))); else return genson.deserialize(genericType, genson.createReader(inputMessage.getBody()), new Context(genson)); }