Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JBPM-10079 ClassCastException when submitting a form in kie-server containing date process variable #2781

Merged
merged 1 commit into from
May 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,16 @@ protected void configureMarshaller(Set<Class<?>> classes, final ClassLoader clas
if (classes == null) {
classes = new HashSet<Class<?>>();
}

// add byte array handling support to allow byte[] to be send as payload
classes.add(JaxbByteArray.class);

if (!formatDate) {
classes.add(Date.class);
classes.add(java.time.LocalDateTime.class);
classes.add(java.time.LocalTime.class);
classes.add(java.time.OffsetDateTime.class);
classes.add(java.time.LocalDate.class);
}

List<NamedType> customClasses = prepareCustomClasses(classes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.apache.commons.io.IOUtils;
import org.assertj.core.util.Arrays;
import org.assertj.core.util.Files;
import org.drools.core.command.runtime.BatchExecutionCommandImpl;
Expand Down Expand Up @@ -317,4 +318,170 @@ public void testLegalizeWrapObjectFieldnames() throws Exception {
BatchExecutionCommandImpl unconverted = marshaller.unmarshall(converted, BatchExecutionCommandImpl.class);
assertEquals("all", ((Order) ((InsertObjectCommand) unconverted.getCommands().get(0)).getObject()).getORDER_ID());
}

@Test
public void testLocalDateTimeWithClasses() throws Exception {
HashSet hs = new HashSet<>();
hs.add(org.kie.server.api.marshalling.Person.class);
hs.add(org.kie.server.api.marshalling.SupportedlDate.class);
Marshaller marshaller = new JSONMarshaller(hs, getClass().getClassLoader(), false, false);

String wrapLocalDateTimeWithType = "{\"person\":{\"org.kie.server.api.marshalling.Person\":{\"fullname\":\"123\",\"dateBirth\":{\"java.time.LocalDateTime\":\"2022-05-19T00:00\"},\"age\":\"21\"}}}";
Map converted = marshaller.unmarshall(wrapLocalDateTimeWithType, Map.class);
assertEquals(org.kie.server.api.marshalling.Person.class, converted.get("person").getClass());
assertEquals(java.time.LocalDateTime.class, ((Person) converted.get("person")).getDateBirth().getClass());

String wrapLocalDateTimeWithoutType = "{\"person\":{\"org.kie.server.api.marshalling.Person\":{\"fullname\":\"123\",\"dateBirth\":\"2022-05-19T00:00\",\"age\":\"21\"}}}";
Map converted1 = marshaller.unmarshall(wrapLocalDateTimeWithoutType, Map.class);
assertEquals(org.kie.server.api.marshalling.Person.class, converted1.get("person").getClass());
assertEquals(java.time.LocalDateTime.class, ((Person) converted1.get("person")).getDateBirth().getClass());

String localDateTimeStringWithType = "{\n" +
" \"bdate\":{\"java.time.LocalDateTime\":\"2022-05-17T14:54\"},\n" +
" \"name\":\"123\",\n" +
" \"bbdate\":{\"java.time.LocalDateTime\":\"2022-05-18T00:00\"}\n" +
"}";
Map converted2 = marshaller.unmarshall(localDateTimeStringWithType, Map.class);
assertEquals(java.time.LocalDateTime.class, converted2.get("bdate").getClass());

String localDateTimeStringWithoutType = "{\n" +
" \"bdate\":\"2022-05-17T14:54\",\n" +
" \"name\":\"123\",\n" +
" \"bbdate\":\"2022-05-18T00:00\"}\n" +
"}";
Map converted3 = marshaller.unmarshall(localDateTimeStringWithoutType, Map.class);
assertEquals(String.class, converted3.get("bdate").getClass());

Map convertedSupportedDateType = marshaller.unmarshall(IOUtils.toString(this.getClass().getResourceAsStream("/supportedDateType.json")), Map.class);
assertEquals(java.time.LocalDateTime.class, convertedSupportedDateType.get("bdate").getClass());
assertEquals(java.time.LocalDateTime.class, convertedSupportedDateType.get("bbdate").getClass());
assertEquals(java.time.LocalDate.class, convertedSupportedDateType.get("localdate").getClass());
assertEquals(java.time.LocalTime.class, convertedSupportedDateType.get("localtime").getClass());
assertEquals(java.time.OffsetDateTime.class, convertedSupportedDateType.get("offsetDateTime").getClass());
assertEquals(java.util.Date.class, convertedSupportedDateType.get("utildate").getClass());

assertEquals(SupportedlDate.class, convertedSupportedDateType.get("sqldate").getClass());

SupportedlDate supportedDate = (SupportedlDate) convertedSupportedDateType.get("sqldate");
assertEquals(java.util.Date.class, supportedDate.getUtildate().getClass());
assertEquals(java.time.LocalDateTime.class, supportedDate.getLocalDateTime().getClass());
assertEquals(java.time.LocalDate.class, supportedDate.getLocalDate().getClass());
assertEquals(java.time.LocalTime.class, supportedDate.getLocalTime().getClass());
assertEquals(java.time.OffsetDateTime.class, supportedDate.getOffsetDateTime().getClass());
}
}

class SupportedlDate {

private java.util.Date utildate;
private java.time.LocalDate localDate;
private java.time.LocalDateTime localDateTime;
private java.time.LocalTime localTime;
private java.time.OffsetDateTime offsetDateTime;

public SupportedlDate() {
}

public java.util.Date getUtildate() {
return this.utildate;
}

public void setUtildate(java.util.Date utildate) {
this.utildate = utildate;
}

public java.time.LocalDate getLocalDate() {
return this.localDate;
}

public void setLocalDate(java.time.LocalDate localDate) {
this.localDate = localDate;
}

public java.time.LocalDateTime getLocalDateTime() {
return this.localDateTime;
}

public void setLocalDateTime(java.time.LocalDateTime localDateTime) {
this.localDateTime = localDateTime;
}

public java.time.LocalTime getLocalTime() {
return this.localTime;
}

public void setLocalTime(java.time.LocalTime localTime) {
this.localTime = localTime;
}

public java.time.OffsetDateTime getOffsetDateTime() {
return this.offsetDateTime;
}

public void setOffsetDateTime(java.time.OffsetDateTime offsetDateTime) {
this.offsetDateTime = offsetDateTime;
}
}

class Person {

private java.lang.String fullname;
private java.lang.Integer age;
private java.time.LocalDateTime dateBirth;
private java.util.Date date;
private java.time.LocalTime localTime;
private java.time.OffsetDateTime offsetDateTime;

public LocalTime getLocalTime() {
return localTime;
}

public void setLocalTime(LocalTime localTime) {
this.localTime = localTime;
}

public OffsetDateTime getOffsetDateTime() {
return offsetDateTime;
}

public void setOffsetDateTime(OffsetDateTime offsetDateTime) {
this.offsetDateTime = offsetDateTime;
}

public Person() {
}

public Date getDate() {
return date;
}

public void setDate(Date date) {
this.date = date;
}

public java.lang.String getFullname() {
return this.fullname;
}

public void setFullname(java.lang.String fullname) {
this.fullname = fullname;
}

public java.lang.Integer getAge() {
return this.age;
}

public void setAge(java.lang.Integer age) {
this.age = age;
}

public java.time.LocalDateTime getDateBirth() {
return this.dateBirth;
}

public void setDateBirth(java.time.LocalDateTime dateBirth) {
this.dateBirth = dateBirth;
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"bbdate": {
"java.time.LocalDateTime": "2022-05-19T10:00"
},
"bdate": {
"java.time.LocalDateTime": "2022-05-19T00:00"
},
"localdate": {
"java.time.LocalDate": "2022-05-19"
},
"localtime": {
"java.time.LocalTime": "17:32"
},
"name": "",
"offsetDateTime": {
"java.time.OffsetDateTime": "2007-12-03T10:15:30+01:00"
},
"sqldate": {
"org.kie.server.api.marshalling.SupportedlDate": {
"utildate": {
"java.util.Date": "2022-05-21"
},
"localDate": {
"java.time.LocalDate": "2022-05-19T00:00"
},
"localDateTime": {
"java.time.LocalDateTime": "2022-05-19T10:00"
},
"localTime": {
"java.time.LocalTime": "17:32"
},
"offsetDateTime": {
"java.time.OffsetDateTime": "2007-12-03T10:15:30+01:00"
}
}
},
"utildate": {
"java.util.Date": "2022-05-21"
}
}
Loading