Skip to content

Instantly share code, notes, and snippets.

@cowtowncoder
Created November 20, 2012 21:58
Show Gist options
  • Save cowtowncoder/4121515 to your computer and use it in GitHub Desktop.
Save cowtowncoder/4121515 to your computer and use it in GitHub Desktop.
Immutable POJO that Just Works with Jackson
/**
* This class works just fine, although you might not think so at first glance.
* Serialization is easy -- just uses getters, after all -- but how about deser?
* Turns out that:
*
* (a) Since Jackson auto-detects private fields (as long as something else indicates
* presence of a property; here getters do it), and
* (b) JDK (1.5+) allows Reflection to force setting of a 'final' value
*
* it... well, works. Try it for fun!
*/
public class ImmutaBean
{
private int x, y;
public int getX() { return x; }
public int getY() { return y; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment