Thursday Feb 19, 2009
Thursday Feb 19, 2009
26. ledna 2009 proběhlo na půdě katedry počítačů, ČVUT FEL, setkání CZJUG na téma webové služby.
Za firmu SUN Microsystems vystoupil Marek Potočiar. Jeho prezentace projektu Metro byla obohacena několika povedenými demonstracemi, kdy jako runtime byl použit aplikační server GlassFish.
Následoval přehled webservices stacku aplikačního serveru JBoss v podání Richarda Opálky z firmy RedHat. Jako bývalého člena Metro týmu mě potěšilo, že i druhá prezentace se tohoto projektu dotkla. JBoss totiž použití Metra nabízí jako jednu z variant.
Slajdy a stručné představení obou přednášejících lze získat na adrese http://java.cz/detail.do?articleId=16971. A pokud vás zajímá víc, podívejte se i na videa dostupná na následujících adresách:
Poznámka: Po downloadu by měla videa být přehratelná na Linuxu/Solarisu mplayerem (vyzkoušeno), z platformy Apple byste je měli být schopni přehrát přímo z webu. Na systémech Windows věřím, že po stažení QuickTime Playeru by přehrání mělo být také bez problémů.
Friday Feb 13, 2009
We have an old bridge in my city. The city is called Prague, and the bridge is called Charles bridge.
Whenever i am passing the bridge, i recall the date when they started construction. It was 1357 9.7. at 5.31 in the morning. Truly magical and exceptional date.
My colleague Pavel told me today, in UNIX world, such a magical date and time happens to come today at 13 11:45:21 PST. Then if you issued the following command for obtaining UNIX time:
perl -e "print time"You got:
1234567890Only UNIX gods know all what came to us with this exceptional second.
Anyway. I have been always curious, how the middle age people managed to start the Charles bridge construction at the very precisely defined point of time. And still have no clue. Then i have decided to do a small experiment. Our blogging infrastructure allows us to publish a blog post at an exact time and date. I am curious to see, how precise will it be. Planning this post to be published at a very magical second. And to keep this on Friday, February 13, even for my time zone, changing the magical number to 1234554321, which seems to me a way more magical, then the poor 1234567890 :-) Will see...
This is an update for a tech tip on configuring JSON in Jersey, which i wrote in October 2008. The way of JSON configuration, suggested in the tech tip, is now deprecated (but still functioning). Here i would like to describe the new API, which will hopefully last (and be supported) a way longer.
Notice: you will need to bundle jaxb-impl-2.1.10.jar
with your application in order to take advantage of the recently added JSON NATURAL convention
Configuring JSON format, as described in the tech tip, meant to implement a JAXBContext resolver
class returning an instance of JSONJAXBContext. This principle have not changed.
What changed is a way, how the JSONJAXBContext itself is being configured.
Lets look at the sample code below (using the deprecated API):
There you needed to create a property bag, put appropriate configuration options into it,
and then pass it to the JSONJAXBContext constructor.
In the currently available 1.0.2 Jersey version, a new JSONConfiguration class was introduced to became a central point for JSON configuration options.
For creating a new JSONConfiguration instance, a builder pattern is employed.
It is not only more user friendly, but also ensures only meaningful JSON options could be combined together.
You can compare the following code, with the deprecated example above:
You can look at JSONConfiguration javadoc for detailed information on various configuration options.
If you go a bit further, you can ask if the configuration could be simplified even more. Imagine you have much bigger number of JAXB beans in your model, and they are more complex. It could easily become unmanageable to maintain a reasonable JSON configuration as described so far. Then if you happen to have conflicting non-string/string values and/or arrays/non-arrays elements in your set, you could easily run out of options there.
A natural way to overcome above mentioned issues, is to simply use recently introduced Jersey NATURAL JSON notation. Then you need only to:
Such configuration is simple from user point of view, but yet very powerful. You do not need to keep various configuration options in sync with your actual JAXB beans, and be worried what options to actually use (what exact names, etc.). Jersey will automatically take care about serializing Java collections/arrays as JSON arrays, Java booleans as JSON booleans, Java ints as JSON integers,and so on.