Rami Muurimäki
Rami Muurimäki

Reputation: 170

XPages REST and date format

I have an XPages page which contains the REST service component. I'm using the "documentJsonService".

Awesome component and everything else is working fine, but I'm having issues with the date formats and don't know what to do.

The Notes Document where I'm reading the data from, contains a DateTime item having a proper date e.g. 01.09.2014 (finnish format: dd.MM.yyyy). The REST component returns the date in "2014-09-01" (string). This is fine. However when I do a HTTP POST to the server with the same exact data, Domino changes the "2014-09-01" string date into 09.01.2014 Notes Date time item.

Don't know any more what to do. Why Domino gives date in format A and when I give it back in same format, something strange happens.

This same happens on Linux and Windows environments. Domino version is 9.0.1.

Thanks already. I'm more or less lost with this "feature" :)

Upvotes: 2

Views: 457

Answers (1)

stwissel
stwissel

Reputation: 20384

I would say: broken as designed. To my knowledge the JSON format returned is always in the form yyyy-mm-dd, while the format expected when posting depends on the browser locale. You would need to "hack around it".

I'm not a big fan of the ready baked JSON services, I'd rather roll my own, where I can be very specific with the formats and (more importantly) add validation before I write data back. You can find a sample on my blog

Basically you implement a bean like this:

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ibm.domino.services.ServiceException;
import com.ibm.domino.services.rest.RestServiceEngine;
import com.ibm.xsp.extlib.component.rest.CustomService;
import com.ibm.xsp.extlib.component.rest.CustomServiceBean;

public class CustomSearchHelper extends CustomServiceBean {

    @Override
    public void renderService(CustomService service, RestServiceEngine engine) throws ServiceException {

        HttpServletRequest request = engine.getHttpRequest();
        HttpServletResponse response = engine.getHttpResponse();

        response.setHeader("Content-Type", "application/json; charset=UTF-8");

        // Your code goes here!

    }
}

you need to check in the request what method GET or POST was used, but then it is easy to continue. While you are on it: the OpenNTF Domino API makes your life much easier.

Upvotes: 1

Related Questions