Java microservice: Custom attributes not getting mapped in ManagedObjectRepresentation when called from RestTemplate

I’m using RestTemplate to get the managed object respresentation. I’m getting the response which is in ManagedObjectRepresentation but the problem is that i’m not getting the custom attributes within the response.
I’m sure some of you would also have faced it. I Appreciate if anyone could help me here.

You can get the custom attributes with .get(“attributeName”) or getProperty("attributeName).
Return type is object so you need to cast them to the type they are representing.

In case of complex custom attributes - where casting would not work - see below example how you can also map custom attributes into java objects:

final Object object = managedObjectRepresentation.get("myObject");
final MyObject myObject = mapper.convertValue(object, MyObject.class);

Sorry i think i dindn’t make my issue clear. The issue is not with mapping the custom property after the response. Its with response mapping itself.
this is my response class.
When response gets mapped to managedObjects property which is list, i dont see the custom properties within attrs property.

Note: This issue is caused only when I explicitly get the managed objects using RestTemplate or WebClient.

What is the reason you are trying to use your own “MoCollection” and not use the SDK inbuilt funcationality?
Can you show the code where you map it into the “MoCollection”?
I believe depending on the response mapping it needs to be defined to map any non-known fields into the “attrs” map - same way as the SDK does it.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.