Setting Date Property in contentnode

I wrote a Repository Job to import a custom RSS-Feed using exim-Plugin.
I am using the newsdocument as document-type.

I get thge following exception, when setting the Date:

Caused by: javax.jcr.ValueFormatException: Single-valued property can not be set to an array of values:property

Here is code to set the date:

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'+01:00'");
String feedDate = formatter.format(feed.getPubDate());
    ...
node.setProperty("osde_40:date",feedDate);

When I set the Date to a fix value like:

node.setProperty("osde_40:date","2020-03-06T12:58:05.707+01:00");

I do not get the error. I logged the output of String-Formatter. The result looks fine.
Here is an example :

[INFO] [talledLocalContainer] 06.03.2020 17:17:00 INFO Hippo JCR Quartz Job Scheduler_Worker-1 [FeedImporter.createFeed:87] Successfully created Document /content/documents/osde_40/markt/feeds/2020/3/6/Jetzt mehr als 100.000 Menschen weltweit infiziert at /content/documents/osde_40/markt/feeds/2020/3/6/Jetzt mehr als 100.000 Menschen weltweit infiziert with pubdate 2020-03-06T16:22:45+01:00

You need to use Calendar instead of String

setProperty does not accept Calendar :frowning:

Maybe not for you, but it does for rest of us :wink:

https://docs.adobe.com/docs/en/spec/jsr170/javadocs/jcr-2.0/javax/jcr/Node.html

I am just puzzled by:
“Single-valued property can not be set to an array of values:property”

Maybe is it because I am using the contentnode of the exim-plugin ?
But at the end I do not unerstand why the hard coded string works and the formatted- which looks the same- not !!!

Try this instead:

import org.apache.jackrabbit.util.ISO8601;
...
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'+01:00'");
String feedDate = formatter.format(feed.getPubDate());
...
node.setProperty("osde_40:date", ISO8601.format(feed.getPubDate());

Difference is whether milliseconds included or not. Use ISO8601.format(...) utility always.

I also tried it with milliseconds included :slight_smile:

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S'+01:00'"); 

and also

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SZ");

But ISO08601.format works :grinning:. I only had to convert Date to Calender

    Calendar feedDate = Calendar.getInstance();
    feedDate.setTime(feed.getPubDate());

Thx for support! :+1: