0

I'm a front-end dev with Java familiarity. I'm having a real tough time pulling up performance & development pros/cons for using methodical conversion vs JSTL for converting Java objects to JSON.

I know that with methodical conversion, an extra layer of getter/setter classes can be used for security - also I've got a really huge hunch that it's just all around faster and less resource intensive, yet I can't find any proof. I can only find comparisons between JSON libraries.

My reasons I need to elaborate on:

  • Stricter security - countered by we control what data is displayed in the JSP
  • Faster, less overhead - countered by lack of proof
  • More easily standardized - countered by lack of flexibility

Here's a few links I've ran into (below) - I'm really looking for some solid research other than a comparison of libraries. Also, if anyone can show me some solid examples of the OJM mapping Jackson offers - that would be awesome.

Once again, I know this is so generic - but I'm just looking for suggestions and proposed reasons why methodical is better than using JSTL.

Community
  • 1
  • 1
Shawn Khameneh
  • 472
  • 4
  • 16

1 Answers1

1

For performance, Jackson is the fast generally used library, according to most public measurements, such as JVM Serializers benchmarks. You can easily test this yourself, or Google for hits (benchmarks exist for Android, Java SE).

Jackson OJM is simple enough. Given object 'ob':

MyObject ob = ...;
ObjectMapper mapper = new ObjectMapper(); // always reuse these, expensive to create
OutputStream out = context.getResponseStream(); // or whateveer

// and then write it out
mapper.writeValue(out, ob);
// or read in:
MyObject ob2 = mapper.readValue(context.getRequestStream(), MyObject.class);

and complications mostly come from either handling of Java generics for Maps, Lists (use TypeReference); non-standard naming conventions (use annotations to define JSON name for Java property name) and such.

Tutorials exist, for example:

Most major Java frameworks are using or will be using Jackson for their JSON conversions: all JAX-RS implementations (Jersey, RESTeasy, CXF), Restlet (2.0), Play (2.0), SpringMVC. It has become de facto standard library due to both efficiency and extensibility, latter being most important for frameworks. Jackson-based JSON processing has also been found to compete favorably with "faster" binary formats (meaning that there is little to gain by switching to using Thrift, Avro or Protobuf, in most web service cases).

Of alternatives, GSON is also widely used, and is as easy to use for data-binding as Jackson.

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
StaxMan
  • 113,358
  • 34
  • 211
  • 239
  • I very much appreciate the response - I guess I was expecting more complex mapping definitions and was looking for something more complex that didn't exist. So the "OJM" is just automated getters and setters? – Shawn Khameneh Sep 24 '12 at 22:18
  • 1
    That is the starting point, and in optimal case, yes, things just match. This is the beauty of JSON that since its information model is based on objects (instead of relational model (SQL) or hierarchic (XML)) it should map in very simple way. There is quite a bit more for some aspects -- like polymorphic types; or to preserve object identity; or how to support immutable types (custom constructors) -- but you can get started very easily. – StaxMan Sep 25 '12 at 04:34