ArrayList overhead; JSon serialization question

43 views
Skip to first unread message

Ulli Gerhard

unread,
Feb 22, 2016, 7:21:17 AM2/22/16
to RestExpress
Hi there - I am currently realising a project utilizing RestExpress.

When looking into the sources from time to time I noticed more than once a "new ArrayList ()", this, by default creates space for 10 instances which leads to unneccessary Memory-allocation.

I think it's safe to replace those with LinkedLists since the performance-gain you get with an ArrayList only shows when they are huge.

If you want to stick with the ArrayLists you can also say "new ArrayList (1)" so the List will be initialized with only 1 allocation.

I really enjoy working with RestExpress, although I only noticed yesterday that I've been using a very old version - still using groupId com.strategicgains.
Since I now updated to version 0.11.3 I always need to specify ?format=json - else I will get xml. Is there a way to make json default (again) ?

Just my 2 cents :)

Ulli Gerhard

unread,
Feb 22, 2016, 7:29:20 AM2/22/16
to RestExpress
Okay - fixed the JSon issue - just do not add the XML_SERIALIZER to SerializationProvider.
I find it confusing that the isDefault parameter in
AbstractSerializationProvider.add is not honored.

Todd Fredrich

unread,
Feb 22, 2016, 11:10:48 AM2/22/16
to RestExpress
Hi Ulli,

Thanks for joining us RestExpressians here!

Regarding your JSON issue, since RestExpress release 0.10.0 it has supported content-type negotiation. So the fact that you're seeing XML is probably because you're using a client that specifies XML before JSON or */* in the Accept header--for example a browser does this. Therefore, what you're seeing is the magic of content-type negotiation at work!

If you don't want to support XML, then doing what you've done is the way to go--and in fact is what I do since it increases your testing effort to support multiple formats. Plus, I've not yet seen anyone request XML payloads an ANY of my APIs as of yet, so it makes sense to just support JSON, IMHO.

Alternatively, use a client that lets you specify the Accept header to provide a value such as 'application/json' or 'application/hal+json' (if you're supporting the HAL media type). PostMan and RestClient browser plugins seem to work well for me. And curl is always good from the command line.

Good luck,
--Todd

Ulli Gerhard

unread,
Feb 23, 2016, 2:28:58 AM2/23/16
to RestExpress
Well I am developing a Webservice that is to be used with normal browsers -
honestly I think totally removing support for xml is not a good thing to do - why would you shrink your feature-set ?

But it should be the default again to response with JSon and only on explicit configuration I'd return xml.

After all it's not a bug - it's a feature ;)

What do you think of the "ArrayList-tipp" I gave you ?
Reply all
Reply to author
Forward
0 new messages