camel salesforce component date time issue

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

camel salesforce component date time issue

ssatguru
camel salesforce component  has issues with dates less than or equal to "November 18th  1883".

These dates are serialized  to a format unacceptable to SalesForce.

For example

Date 1800-01-01 is serialized by this component as

1800-01-01T00:00:00.000-05:50:36

Salesforce responds with the following error

{message:'{errors:[{"errorCode":"JSON_PARSER_ERROR","message":"Cannot deserialize instance of date from VALUE_STRING value 1800-01-01T00:00:00.000-05:50:36 ...

The problem has to do with the seconds in the time zone part (:36 in above example)

The issue arises because camel salesforce component use the Joda DataTime library which handles date before "November 18th  1883" in this manner

see here for some discussion on this

https://www.kevinhooke.com/2010/07/23/whats-the-significance-of-nov-18th-1883-to-software-development-in-the-us/

or

http://stackoverflow.com/questions/14282423/why-when-year-is-less-than-1884-it-remove-few-milliseconds

Maybe the salesforce component should convert the date or date time to milliseconds format rather than the zoned format. Salesforce  seems to accept this format

Reply | Threaded
Open this post in threaded view
|

Re: camel salesforce component date time issue

arno noordover
This post was updated on .
Hmm, I had the same problem communicating with WCF. I generated classes from a wsdl containing jodatimes and used a simple conversion to convert this to a string. I needed to create a special jodatime-format which didn't contain the seconds part in the time-zone offset.
Although it is technically correct, the xsd datetime don't expect seconds in de timezone-offset.

Line 43 of JodaTimeConverter uses the ISODateTimeFormat, which has a complex algorithm to convert a datetime to a String. The question is whether it needs to be this complex.
A further question is what datetime-formats salesforce supports.
Does it support 2005-084 as day 84 of the year 2005?

Does anybody have inside information about this?
Of course I will google on this...

https://help.salesforce.com/HTViewSolution?id=000004680&
Reply | Threaded
Open this post in threaded view
|

Re: camel salesforce component date time issue

Claus Ibsen-2
In reply to this post by ssatguru
On Sat, Jun 25, 2016 at 5:23 PM, ssatguru <[hidden email]> wrote:
> camel salesforce component  has issues with dates less than or equal to
> "November 18th  1883".
>

I am intrigued to hear what is the use-case is for using dates going
so far back?

And if there is such a problem, has it been reported to jodatime ?
Maybe there is a fix already in a newer version?



> These dates are serialized  to a format unacceptable to SalesForce.
>
> For example
>
> Date 1800-01-01 is serialized by this component as
>
> 1800-01-01T00:00:00.000-05:50:36
>
> Salesforce responds with the following error
>
> {message:'{errors:[{"errorCode":"JSON_PARSER_ERROR","message":"Cannot
> deserialize instance of date from VALUE_STRING value
> 1800-01-01T00:00:00.000-05:50:36 ...
>
> The problem has to do with the seconds in the time zone part (:36 in above
> example)
>
> The issue arises because camel salesforce component use the Joda DataTime
> library which handles date before "November 18th  1883" in this manner
>
> see here for some discussion on this
>
> https://www.kevinhooke.com/2010/07/23/whats-the-significance-of-nov-18th-1883-to-software-development-in-the-us/
> <https://www.kevinhooke.com/2010/07/23/whats-the-significance-of-nov-18th-1883-to-software-development-in-the-us/>
>
> or
>
> http://stackoverflow.com/questions/14282423/why-when-year-is-less-than-1884-it-remove-few-milliseconds
> <http://stackoverflow.com/questions/14282423/why-when-year-is-less-than-1884-it-remove-few-milliseconds>
>
> Maybe the salesforce component should convert the date or date time to
> milliseconds format rather than the zoned format. Salesforce  seems to
> accept this format
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/camel-salesforce-component-date-time-issue-tp5784399.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



--
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2
Reply | Threaded
Open this post in threaded view
|

Re: camel salesforce component date time issue

arno noordover
This post was updated on .
For us the usecase had to do with the default minimal datetime used by WCF when you don't set a non nullable datetime in C#.
C# fills this datetime with 1-1-0001 and some time-part.

So really not salesforce related of course.
My solution was to provide my own formatter
    private final DateTimeFormatter formatter = new DateTimeFormatterBuilder()
            .appendYear(4, 4)
            .appendLiteral('-')
            .appendMonthOfYear(2)
            .appendLiteral('-')
            .appendDayOfMonth(2)
            .appendLiteral('T')
            .appendHourOfDay(2)
            .appendLiteral(':')
            .appendMinuteOfHour(2)
            .appendLiteral(':')
            .appendSecondOfMinute(2)
            .appendLiteral('.')
            .appendMillisOfSecond(3)
            .appendTimeZoneOffset("Z", true, 2, 2)
            .toFormatter();

What the use-case might be here I don't know.
By the way, I'm trying to test this with normal jodatime (say yesterday) and the 2.18-SNAPSHOT version of salesforce seems to fail with all the datetime fields.

Of course I'm not sure about my findings because it isn't easy to test against salesforce.

In my tests I seem to need a jackson SimpleModule:
public class DateTimeModule extends SimpleModule {

    public DateTimeModule() {
        super();
        addSerializer(DateTime.class, new DateTimeSerializer());
        addDeserializer(DateTime.class, new DateTimeDeserializer());
    }
}

For now it might be enough for this usecase to add an objectMapper to the salesforce-configuration using the existing uri-param objectMapper.
**********************************
Hmm, this was introduced in 2.18...
**********************************
Maybe we don't need to support this usecase in Camel.
Reply | Threaded
Open this post in threaded view
|

Re: camel salesforce component date time issue

arno noordover
I've got an update.
In 2.17.x we use jackson 1.9.12
In 2.18 we use a jackson 2.xx version

2.17.x:
* Normal jodatimes (as in not too old) don't fail;
* Old jodatimes (as in 1-1-1800) fail.

2.18:
* Normal jodatimes fail;
* Old jodatimes fail.

I propose to implement my proposed solution for 2.18 and try to cherry-pick it in 2.17.
I already created https://issues.apache.org/jira/browse/CAMEL-10090
Who will decide what to do?
Reply | Threaded
Open this post in threaded view
|

Re: camel salesforce component date time issue

ssatguru
In reply to this post by ssatguru
So the use case for using 1800-01-01in our case was, to some extent, arbitrary.
Business needed some arbitrary, very old date for some data.
We got around the issue by choosing 1900-01-01 instead.

The problem of course is valid.

One solution could be to pass date in milliseconds (i.e. number of milliseconds since January 1, 1970, 00:00:00 GMT)
Salesforce seems to accept that. Need to get some verification on that though.

Here's the relevant Camel SaleForce component code
https://github.com/apache/camel/blob/master/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/internal/processor/JsonRestProcessor.java#L59

replacing
this.objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
with
this.objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, true);

results in milliseconds.

Not sure of any other other side effects of this.






Reply | Threaded
Open this post in threaded view
|

Re: camel salesforce component date time issue

arno noordover
I decided to implement the raised issue only for 2.18.0, because the use-case for old dates in salesforce isn't very clear.
This decision was made on the fact that 2.18.0 didn't support jodatime at all and this was a regression.
Reply | Threaded
Open this post in threaded view
|

Re: camel salesforce component date time issue

arno noordover

Do we help the community (lower footprint) when we switch from jodatime to java8 zoneddatetime?

Op 27 jun. 2016 8:33 p.m. schreef "arno noordover [via Camel]" <[hidden email]>:
I decided to implement the raised issue only for 2.18.0, because the use-case for old dates in salesforce isn't very clear.
This decision was made on the fact that 2.18.0 didn't support jodatime at all and this was a regression.



If you reply to this email, your message will be added to the discussion below:
http://camel.465427.n5.nabble.com/camel-salesforce-component-date-time-issue-tp5784399p5784467.html
To unsubscribe from camel salesforce component date time issue, click here.
NAML