Category Archives: Java

Fun with Jackson Serialization

Spending some quality time this weekend walking through the deeper layers of Jackson JSON serialization. I’ve used the library casually in the past, but never for anything of any great complexity. It has recently come up as a target for some more complicated (harder to map directly into JSON) data structures. I’m spending a few hours this weekend putting together some sample code to ring the changes on things I might want Jackson to do.

Initial sample code bits are just walking through the basics and making sure I remember what is needed there. I am noticing a few things:

  • It doesn’t care about serializable at all. I expect that it uses reflection to walk the object tree and find property accessors directly.
  • It demands getters and setters for all properties to be serialized. A constructor with the appropriate arguments is not an option. This means that immutable-ish objects are not supported. You must be able to read and write object properties individually to make Jackson work.
  • It does respect transient so it is easy enough to mark internal implementation details for exclusion from processing.
  • The object mapper does not like objects with more than one single argument setter, even if one setter exactly matches the type being loaded into the de-serialized object.

Next step is going to be creating a map of string to custom object.

So far I’ve done the easy stuff. Some evening soon I’ll try to find time to add in the more complicated bits. Code is here.

And now custom object that is a proper map key (implements hashCode and Equals) to custom object.

JavaFX Event Handling

I’m finding myself needing a better understanding of JavaFX UI event handling and my basic JavaFX books seem to ignore most of that aspect of the system. It looks as if the wiring of UI events is buried deep enough and the handling is automated enough that most of the time there’s no need to directly interact with events.

I need to perform an action when a given UI panel is exposed after being hidden…a simple enough activity in most cases. I expect I’ll find the right controls soon enough, just a bit surprised that they’re not talked about as directly as I’m used to.

Looking as if the easy route to this may be to name the top level pane in a given area and then attach a ‘show’ handler to that pane. Hoping this works as this would make it pretty easy to do what I need to get done.

Some links that I’m recording for later convenience (some just interesting here not directly relevant):

The charting and 3D API items are of interest, but not part of this, but I’m trying to keep notes on where things were found so that I can go back and dig deeper later…a small amount of clutter for convenience…

Java Tasks don’t do Lambdas

I was spinning a thread recently and it was pointed out to me that the environment I was working in at the time used Task (JavaFX code) for such things. My thread was being created with a Lambda expression as the action to be performed. It surprised me when I could not directly translate that to a Task.

After a bit of research I found this post discussing why that is the case (as a side-effect of the fact that Task is an abstract class). As with so many things in Java where the choice is to accept less expressive and longer winded approaches to limit language level complexity, I’m not sure I agree with the choice, but it is what it is at this point.

Adding in the anonymous local class framing isn’t a big deal and that’s clearly the way to go for this item.