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 b68af07
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
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 All @@ -261,7 +264,7 @@ protected void configureMarshaller(Set<Class<?>> classes, final ClassLoader clas

// setup custom serialization mapper with jaxb adapters
customSerializationMapper.configure(MapperFeature.USE_STD_BEAN_NAMING, this.useStrictJavaBeans);
customSerializationMapper.setConfig(customSerializationMapper.getDeserializationConfig().with(introspectorPair));
customSerializationMapper.setConfig(customSerializationMapper.getDeserializationConfig().with(introspectorPair).with(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY));
customSerializationMapper.setConfig(customSerializationMapper.getSerializationConfig().with(introspectorPair).with(SerializationFeature.INDENT_OUTPUT));

// in case there are custom classes register module to deal with them both for serialization and deserialization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,88 @@ 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;
private java.util.Date date;
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;
}

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 b68af07

Please sign in to comment.