Spring Boot - 3.1.2 Spring Cloud Function Version -4.0.5
Hi,
I am using RoutingFunction of the spring cloud. (this is link to the sample code base - https://github.com/Mohit-Sardiwal/inheritance which I am explaining below)
Lets say I have Parent class , Child class which extends Parent and GrandChild which extends Child class.
I am using parent reference and GrandChild object to store the below json string payload
ObjectMapper objectMapper = new ObjectMapper();
Object jsonObject = objectMapper.readValue(jsonString, GrandChild.class);
Parent parent = (Parent)jsonObject ;
Json String
{
"id": "4a001",
"name": "John",
"childId": "12345",
"value": "first",
"properties": {
"hobbies": [
{
"hobbyId": "1",
"hobbyName": "coding"
}
]
}
}
I am making list of the above Parent object and making spring message out of it and passing that message to routingFunction
List<Parent> parentList = new ArrayList<>();
parentList.add(parent);
Message object = (Message) MessageBuilder.withPayload(parentList).build();
Message functionMessage = MessageBuilder.withPayload(object.getPayload())
.setHeader("spring.cloud.function.definition","getFamilyData")
.setHeader(MessageHeaders.CONTENT_TYPE,"text/plain").copyHeadersIfAbsent(object.getHeaders))).build();
in my function (getFamilyData) I am expecting list of Child (as shown below). But I when I am using CONTENT_TYPE as text/plain I am getting empty list in FxGetFamilyData function and when I am not passing CONTENT_TYPE then I am getting list but in that I am only getting Child data . Grand Child data is not there.
@bean
public Function<List, List> getFamilyData() {
return new FxGetFamilyData();
}
public class FxGetFamilyData implements UnaryOperator<List> {
@OverRide
public List apply(List children) {
log.debug("Received Event :{}",children);
return children;
}
}
When ContentType is text/plain:
Received Event :[]
When ContentType is not send in headers (Not able to receive GrandChild data)
Received Event :[Child(childId=12345, value=first)]
Classes:
public class Parent {
private String id;
private String name;
}
public class Child extends Parent{
private String childId;
private String value;
}
public class GrandChild extends Child{
private GrandChildProperties properties;
}
public class GrandChildProperties {
private List hobbies;
}
public class Hobbies {
private String hobbyId;
private String hobbyName;
}