Skip to content

Commit

Permalink
JBPM-10079 ClassCastException when submitting a form in kie-server co…
Browse files Browse the repository at this point in the history
…ntaining date process variable
  • Loading branch information
bxf12315 committed May 19, 2022
1 parent 2a211c6 commit 7870c5e
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,11 @@ 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);
classes.add(java.time.LocalDateTime.class);

if (!formatDate) {
classes.add(Date.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,79 @@ 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);
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());
}

}

class Person {
private java.lang.String fullname;
private java.lang.Integer age;
private java.time.LocalDateTime dateBirth;
public Person() {
}

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;
}

public Person(java.lang.String fullname, java.lang.Integer age,
java.time.LocalDateTime dateBirth) {
this.fullname = fullname;
this.age = age;
this.dateBirth = dateBirth;
}

}

0 comments on commit 7870c5e

Please sign in to comment.