suvallur / rest-assured

Automatically exported from code.google.com/p/rest-assured
0 stars 0 forks source link

integrate with johnzon #371

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

current json is handled with gson or jackson. Would be great to integrate 
johnzon.

A new release is coming (0.2-incubating) in few days so maybe wait 1 or 2  
weeks before working on this task but here is what I use in my current app:

    RestAssured.objectMapper(new ObjectMapper() {

            // all these sets are optional but makes the behavior closer
            // to jackson, defaults use getter/setter only
            // and private constructors are not supported
            private final Mapper mapper = new MapperBuilder().setAccessModeName("field").setSupportHiddenAccess(true).build();

            @Override
            public Object deserialize(final ObjectMapperDeserializationContext context) {
                final Class<?> type = context.getType();
                final InputStream entityStream = context.getDataToDeserialize().asInputStream();
                if (type.isArray()) {
                    return mapper.readArray(entityStream, type);
                }
                return mapper.readObject(entityStream, type);
            }

            @Override
            public Object serialize(final ObjectMapperSerializationContext context) {
                final StringWriter stream = new StringWriter();
                mapper.writeObject(context.getObjectToSerialize(), stream);
                return stream.toString();
            }
        });

Original issue reported on code.google.com by rmannibucau@gmail.com on 11 Nov 2014 at 7:19

GoogleCodeExporter commented 9 years ago
Do I understand it correctly that johnzon is an implemention of the 
JsonProcessing JSR that will be available in Java 9? In that case I think it's 
very important to have support for it. 

Thanks for the example

Original comment by johan.ha...@gmail.com on 13 Nov 2014 at 6:38

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
No no, it implements the jsonp spec of JavaEE 7

Original comment by rmannibucau@gmail.com on 13 Nov 2014 at 7:47

GoogleCodeExporter commented 9 years ago
Alright, thanks for clarifying :)

Original comment by johan.ha...@gmail.com on 14 Nov 2014 at 6:10