Same origin policy and jsonp, Nice article by Zack grossbart


Using jaxb, you might run into problems with serializing dates:

I wanted to set up a server side REST server using Jersey (1.4 and lower): my java beans are correctly serialized towards JSON  (natural notation) , so my client app (eg. GWT or just javascript inside html) can parse it.

So I used the JAXB @XmlRootElement annotation to annotate my javabeans, and all works fine: jersey serializes the javabeans into application/json (in natural notation) which can easily be parsed inside the browser (in my case GWT)

However, if a javabean has a java.util.Date value, and this date has 0 milliseconds, the date string serialized does not contain the mandatory “.000” millis, in fact, jaxb drops of those “redundant” millis. So this makes the date not compatible with the ISO8601 standard “yyyy-MM-dd’T’HH:mm:ss.SSSZ”. So at client side, we allways set this dateformat in GWT, but if the data has no milliseconds in the String, the dateparser of GWT throws an exception that the date value is not compatible with the format, and which is true.

As a workaround, I tried many thing, first upgraded from Jersey 1.1 to 1.4, same problem. Then I tried a native Jackson (json lib) test, since Jersey also uses Jackson. There (Jackson 1.5.5) you can set a custom marshaller/unmarshaller using annotations, but then every DTO with a Date needs to have this annotation (which points to the (un)marshaller). A better solution within Jackson is to set the default date format in the ObjectMapper configuration.

Using JAXB

In any case, I am using the JAXB/Json way within Jersey, and not the POJO way. The POJO init parameter in the web.xml for jersey tells Jersey to use Jackson. So I needed to find an easy JAXB solution. Within JAXB it is easy to define a custom adapter: you annotate all your Date variables or getters with “@XmlJavaTypeAdapter”, or you create a file in each package containing DTO’s to be serialized:

Sample (to be copied in all packages having dates !, note: annotations may not end with ‘,’ it will compile in eclipse but not with javac or maven)

@javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter(value=be.xx.MyJaxBDateAdapter.class,type= java.util.Date.class)


The adapter looks like:

public class MyJaxBDateAdapter  extends XmlAdapter<String,Date>

//public static final String DATEFORMAT=”yyyy-MM-dd’T’HH:mm:ss.SSSZ”;//standard jaxb/resty ISO8601 date format
public static final String DATEFORMAT=”yyyy-MM-dd’T’HH:mm:ssZ”;//without millis

public MyJaxBDateAdapter(){}

public Date unmarshal(String s)    throws Exception    {
if(s==null || s.equals(“”))
return null;

SimpleDateFormat sdf=new SimpleDateFormat(DATEFORMAT);
return sdf.parse(s);

public String marshal(Date d)     throws Exception     {
return “”;

SimpleDateFormat sdf=new SimpleDateFormat(DATEFORMAT);
return sdf.format(d);


Using Jackson

If you don’t want to use Jaxb beans but just pojos, just tell Jersey to use Jackson (init param in web.xml JSONConfiguration.FEATURE_POJO_MAPPING to true or add a @Provider class like here) , there are 2 ways: or use the annotation @JsonSerialize on every date, or set the default date format.
* way to configure so that Jersey uses jackson as json serializer
* using the provider annotation
* see also
* this is needed for the bug we have in the standard json serializer with date objects
* having 0 millis: the millis are dropped off
* 2 ways to solve it with jackson:
* a) add an @JsonSerialize annotation on the getter of the dto/pojo (this means all objects with dates need to have this annotation on all date getters)
* b) set it general for all dates:  om.getDeserializationConfig().setDateFormat(sdf) and    om.getSerializationConfig().setDateFormat(sdf);
* => b) is best scenario since we do not need jackson annotations on all dto’s having dates


public class MessageBodyWriterJSON extends JacksonJsonProvider{
private static final String DF=”yyyy-MM-dd’T’HH:mm:ss.SSSZ”;

public MessageBodyWriterJSON(){

//    @Override
//    public long getSize(Object arg0, Class arg1, Type arg2, Annotation[] arg3,
//            MediaType arg4) {
//        // TODO Auto-generated method stub
//        return -1;
//    }
public boolean isWriteable(Class arg0, Type arg1, Annotation[] arg2,
MediaType arg3) {
// TODO Auto-generated method stub
return super.isWriteable(arg0, arg1, arg2,
//return true;
public void writeTo(Object target, Class arg1, Type arg2, Annotation[] arg3,
MediaType arg4, MultivaluedMap arg5, OutputStream outputStream)
throws IOException, WebApplicationException {
SimpleDateFormat sdf=new SimpleDateFormat(DF);

ObjectMapper om = new ObjectMapper();

try {
om.writeValue(outputStream, target);
} catch (JsonGenerationException e) {
throw e;
} catch (JsonMappingException e) {
throw e;
} catch (IOException e) {
throw e;



Jaxb vs. Jackson serialization:

-dates are default 1970-millis in jackson, ISO8601 in jaxb

-no support for transient in jackson?

– maps are serialized differently





After reading about the new features about 1.5, I was quite excited, since some of the issues I had were solved, and some more extra features were added like the camcorder.

Moreover, the SDK / language offered some new features regarding multi-threading and layout. I found this nice video on youtube where someone showed the new features.

Installing it on the original dev phone (not the T-mobile !!) is quite easy: go to HTC website and download the radio image zip file and the recovery image zip file.

Firstly I downloaded the radio image, renamed it to and put it on the root of the SD card. Then shut down the phone and reboot it with home+poweroff pressed. Then ALT-L and ALT-S (lowercase L and S) and the radio firmware was upgraded

Secondly I downloaded the recovery image, renamed it to and put it again on the root of the sd card. Same procedure: shut down the phone, reboot it with home/poweroff, ALT-L and ALT-S. Then it takes a while, but it gets installed.

So all the things mentioned on the htc website are not really needed (adb or fastboot). I upgraded my android in 15 minutes… without the need of the SDK which I had installed anyway.

One of the nice things is that all my data was preserved: contacts, calendar, pictures, my saved tracks in ‘mytracks’….

Previously I had issues with my SD card mounted in read only mode, so the camera could not save pictures, etc… I had to launch in a terminal emulator on the G1 the command: mount -o rw,remount,dirsync -t vfat /dev/block/mmcblk0p1 /sdcard . Now this is solved.

Another thing which is great is that the shutter time of the camera is much smaller and that there is a softbutton to take the picture. The hard-button is really annoying.

One small issue: I had to download the new GPS Status application since the old crashes on 1.5.

See also this website for upgrading…

Tip: try out the barcode application, this is quite cool too..

Upgrading the phone was a breeze…

I hope they fixed my Maven plugin bug in netbeans 6.7 beta, download it from the website. (see also my netbeans page.)

I’ve installed the zip file on linux, a 250MB download tarball ! The full installed version is 550MB. For some reason it did not correctly install openesb, glassfish21 and tomcat6, Maybe a conflict with my already netbeans 6.5 installation ?

Nevertheless the basic ide installed ok. Starting up is ok. It looks really slick.

When started, I was looking to install the maven plugin (as  you had to do in netbeans 6.5). Surprisingly, it is installed by default, cool !

The next thing I did, is I downloaded my maven multi module project (zip file) from my netbeans issue. The goal is to have the classic maven approach:

  1. root pom which encapsulates everything (aka build all)
  2. a parent pom for project inheritance
  3. a foo service interface: this has an interface class which will be used in the other module (WelService)
  4. a foo rating service, which extends the foo service interface (RateService)

The whole idea is that if I change the api definition of my WelService interface in the foo service interface module, the impact (build failure) must be visible in the foo rating service module (RateServiceImpl).

  1. First things first, into the netbeans options / maven , i defined my maven repository folder.
  2. Next i added my own build configuration with the goals “clean install”. Apparently this is not longer needed in 6.7, it is by default, so you can skip this.
  3. After extracting the maventest zipfile you can open it natively, “Open Project”. Netbeans will detect the root pom and submodules. The IDE shows it nicely (better than in 6.5)
  4. Next, build first the “parent”  project
  5. Next, build the service-interface module
  6. Next build the rating service module, you will see the compilation failure in the maven console.
  7. Fix the build error in RateServiceImpl, now everything builds fine.
  8. If you change the WelService interface again (add method) and save it, you even don’t have to “rebuild” it manually, when you go to RateServiceImpl, the error will show immediately without the maven rebuild. The only little bug is that the icon of the RateServiceImpl file/package does not color red. if you add a empty line and save it then it will do so.

As an extra feature, the right-click-menu on a maven project has some nice extras like the dependency graph

In short, it is really cool and promising, I do hope they will fix the icon bug

Now I’ve imported a 34 module project with root/parent structure, all seems to be fine, as long as you’ve built them once with Maven (clean install) and installed them in your local repo.

However, one module is a xmlbeans project wich does not have sourcefiles in src/main/java, they are generated from XSD’s. Even if the other modules have a maven jar dependency (and it is  shown in the libraries folder), netbeans marks the classes in the modules using those xml-type beans as error. The workaround is to exclude it from your root pom, so there is only a library dependency and not a netbeans/maven project.