AnsweredAssumed Answered

Submit a date variable in rest

Question asked by ludopaquet1 on May 27, 2013
Latest reply on May 29, 2013 by ludopaquet1
Hello community,

I found that it's impossible (in 5.12.1) to store a date variable usin the REST interface. It seems that SecuredResource.retrieveVariables only scans for long, double, string values.

Can you confirm that it's not a misunderstanding from me before I write a jira ticket ?

For the moment I use a workaround in overriding this method with this piece of code :

Map<String, Object> variables = new HashMap<String, Object>();      

        if (jsonNode != null) {
            Iterator<String> itName = jsonNode.getFieldNames();
            while (itName.hasNext()) {
                String name = itName.next();
                JsonNode valueNode = jsonNode.path(name);

                if (valueNode.isBoolean()) {
                    variables.put(name, valueNode.getBooleanValue());
                } else if (valueNode.isInt()) {
                    variables.put(name, valueNode.getIntValue());
                } else if (valueNode.isLong()) {
                    variables.put(name, valueNode.getLongValue());
                } else if (valueNode.isDouble()) {
                    variables.put(name, valueNode.getDoubleValue());
                } else if (valueNode.isTextual()) {
                    //START WORKAROUND
                   ObjectMapper map = new ObjectMapper();
                   DateFormat df = map.getDeserializationConfig().getDateFormat();
                    String textValue = valueNode.getTextValue();
                    try {
                        Date dateValue=df.parse(textValue);
                        variables.put(name, dateValue);
                    } catch (ParseException pe) {
                        variables.put(name, valueNode.getTextValue());
                    }
                   //END WORKAROUND
                   
                } else {
                    variables.put(name, valueNode.getValueAsText());
                }
            }
        }
        return variables;

Outcomes