Of Code and Me

Somewhere to write down all the stuff I'm going to forget and then need

Getting Json.Net and Gson json libraries to play nicely with dates using ISO formatting January 28, 2011

Filed under: C#,Java,Web,WebServices — Rupert Bates @ 2:38 pm

I am working on something at the moment where I have a service written in .net which serves json created using the Json.Net library. This is then consumed by a client app written in Java which uses the Gson library to deserialize that json into Java classes. This was all working fine except for dates which caused parse errors in Gson.

The solution I am using is:

use ISO time format when serializing with Json.Net

    string json = JsonConvert.SerializeObject(entry, new IsoDateTimeConverter());    

When Deserializing with Gson set the date format as follows:

        GsonBuilder b = new GsonBuilder();
        b.setDateFormat("yyyy-MM-dd'T'HH:mm:ss");
        Gson gson = b.create();
        gson.fromJson(json, MyObjectType.class);
Advertisements
 

Error .apk.res not found In IntelliJ Idea Android project January 27, 2011

Filed under: Android,Error,Git,IntelliJ,Java — Rupert Bates @ 10:32 am

After pulling the latest source of an android project I am working on from GitHub I got the following error:


MyProject.apk.res not found. Try to rebuild project

But no amount of rebuilding would fix it.
It turned out that the problem was that somehow the Module had lost track of which Android platform it is targeted to. To fix it I did the following:

  1. Bring up the Project Structure dialog (File/Project Structure or ctrl+alt+shift+s)
  2. Make sure that Modules is selected in the Project settings pane (far left)
  3. Expand the node with the name of your project in the middle pane and click on the Android node underneath it. This selects the Android facet.
  4. At the top of the Facet pane there is a drop-down list which you can use to select your Android platform. If there are no entries in this you can create a new one by clicking ‘New’ and locating the directory your Android SDK is installed in.
  5. Click Ok and rebuild, the problem should now be fixed

It seems that the problem is caused by Git in some way, but I’m not exactly sure how yet. I’ll update here if I find out why.