cancel
Showing results for 
Search instead for 
Did you mean: 

Submit a date variable in rest

ludopaquet1
Champ in-the-making
Champ in-the-making
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;
2 REPLIES 2

frederikherema1
Star Contributor
Star Contributor
That is indeed correct. The new REST implementation (as of 5.13, existing REST will be kept alongside of the new impl) will allow you to submit ISO-dates and has a pluggable mechanism to support custom types on top of all type supported by the engine right now.

ludopaquet1
Champ in-the-making
Champ in-the-making
Great ! Thanks.