Accessing Context of Serializing Object from Serializer
See original GitHub issuepublic class UserProfile{
Integer userId;
Gender gender;
@JsonPhotoUserUrl
Integer photoId;
}
@Retention(RetentionPolicy.RUNTIME)
@JsonProperty("photoUrl")
@JsonSerialize(using = JsonPhotoUserUrlSerializer.class)
public @interface JsonPhotoUserUrl {
}
We would like to serialize photoId as a URL. However there are some users who have not a photo yet and for these conditions we would like to show a default picture according to gender. For this case we desperately need the gender.
Please provide a way to access object which is being serialized.
Issue Analytics
- State:
- Created 10 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Serializers - Django REST framework
Serializers · Declaring Serializers · Serializing objects · Deserializing objects · Saving instances · Validation · Accessing the initial data and ...
Read more >Serializing context on Django CBV? - Stack Overflow
1 · I wish to get the data in the context to a JSON format, E.g 'organization_user': <OrganizationUser: Erik (MyOrgName)> so I can...
Read more >Serializers - Django REST framework - Tom Christie
We'll declare a serializer that we can use to serialize and deserialize Comment objects. ... The first part of serializer class defines the...
Read more >Serialization and custom serializers - Orleans - Microsoft Learn
[SerializerMethod] static private void Serialize( object input, ISerializationContext context, Type expected) { // ... } As with copiers, the " ...
Read more >Serialization Context in O3DE - Open 3D Engine
Serializers are a useful way to provide custom data formats. If you want to do custom processing on an object before writing or...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It looks like some generic context passing mechanism would be very useful. I need to serialize a field depending on the information not inherent to the object(s) being serialized but to the thread that is serializing. For instance, I have a message object with payload and headers, I’d like to convert its payload to JSON (or back) with some fields represented in different format (like string literal or numeric value for Enums) depending on the initial message header value, which is not part of the object tree being converted. Creating a new ObjectMapper with custom (de)serializers for each message to achieve the goal looks expensive.
Actually, #631 does this with 2.5.0 (due to release soon).