This is a notification of changes being made internally in the serializers and parsers.  Existing APIs and behavior are unchanged.

The major change is that SerializerSession and ParserSession objects are now reusable as long as they're reused within the same thread.  They used to be throw-away objects that would only exist for the duration of a single serialization/parse.

// Old way (still works)
JsonSerializer.DEFAULT.serialize(writer1, pojo1);
JsonSerializer.DEFAULT.serialize(writer2, pojo2);

// New way now possible
SerializerSession session = JsonSerializer.DEFAULT.createSession();
try {
  session.serialize(writer1, pojo1);
  session.serialize(writer2, pojo2);
} finally {
session.close();
}  
 

The original driver behind this change was so that the existing HtmlSerializerSession can be used in the MenuItemWidget (and other widgets) to serialize POJOs to match the formatting rules on the rest of the page. 

Internally, the actual serialization and parsing code has been moved from the Serializer/Parser subclasses into the Session classes.  This had the nice side effect of allowing me to eliminate many of the getter methods on the session objects and replace them with references to private final fields which cleaned up the code quite a bit.  There might be some slight performance improvements, but the GIT compiler was probably already inlining much of this code.

Session objects are rather cheap to create, but they do still involve setting 20+ private final fields.  So I can envision the sessions being reused when ultra-efficiency is needed.  But again the usecase would be limited since they're not designed to be thread safe.

 

  • No labels