JsonSubTypes | Discriminated Json Subtypes Converter implementation | Serialization library
kandi X-RAY | JsonSubTypes Summary
kandi X-RAY | JsonSubTypes Summary
JsonSubTypes is a discriminated Json sub-type Converter implementation for .NET.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of JsonSubTypes
JsonSubTypes Key Features
JsonSubTypes Examples and Code Snippets
Community Discussions
Trending Discussions on JsonSubTypes
QUESTION
Disclaimer
I know there are many posts with a similar problem, but no solution is working for me. I've been trying since yesterday and the amount of attempts I tried are too many to be listed here. What I'm posting is the latest attempt.
Overview
I have a service, that sends a request to another service and needs to deserialize the response polymorphically.
Classes
This is the format I receive from the rest call. Only two properties.
...ANSWER
Answered 2022-Apr-09 at 12:28The first thing you need to do is remove the unnecessary @JsonProperty("type")
:
QUESTION
I have a data model called Project
which is lifecycled from an Angular app via Spring Data Rest. The Project
has Scene
s, Scenes have UpstreamKey
s held in a Map
and UpstreamKey
is an abstract class with two implementations ChromaKey
and LumaKey
. (see code below)
When I edit (PUT
) and existing Project
with a ChromaKey
in the map, and change that to a LumaKey
, I get an error message in the backend:
ANSWER
Answered 2022-Apr-05 at 02:03Though I can achieve the update in spring data mongodb, it's not possible in spring data rest now. In current spring data rest implementation, a PUT request try to merge the nested collection member by calling DomainObjectReader.mergeForPut(...)
which fails on type mismatch, rather than replace it. See this github issue and pull request.
So the workaround is implement a controller yourself.
Edit 2022-04-05Annotate UpstreamKey
with @Immutable
make spring data rest perform replacement rather than merge. This solution only works if the nested collection member is just value (no id, no audit data, no @JsonIgnore to hide server side data) instead of entity (with id).
Find the updated project and the diff
Below is result mongo data after the put opertaion.
QUESTION
Question :
Do I need to remove generic on my interface IAbstractUserService ?
Is it related to this answer with type erasure ? https://stackoverflow.com/a/31266152/6698175
Problem :
I'm getting this exception :
org.hibernate.WrongClassException: Object [id=1] was not of the specified subclass [com.faz.idb.models.Adviser] : loaded object was of wrong class class com.faz.idb.models.Customer
when trying to load entity with :
...ANSWER
Answered 2022-Mar-19 at 11:11Problem solved.
I was using @MapsId without @JoinColumn(name="id") in the child entity of @OneToOne relation.
Explanation:
"AbstracUser" is extended by a "Customer" entity and he has @OneToOne relation with "PersonDetails".
So in Customer I had :
QUESTION
Let's say I have the following classes:
...ANSWER
Answered 2022-Feb-09 at 19:24The best way to achieve this is through a mixin.
Here's an example:
QUESTION
I need to deserialize JSON looks like the following:
...ANSWER
Answered 2022-Jan-26 at 22:14Right now it is not clear what is the exact root cause of the problem, because your example works for me with several corrections.
Still, please, consider the corrections as a draft.
Corrections Data class for root object: IntroducedQUESTION
I am new in Jackson and I need to deserialize JSON looks like the following:
...ANSWER
Answered 2022-Jan-06 at 12:21You actually need to use @JsonTypeInfo
and @JsonSubTypes
in an abstract Company
as follows:
QUESTION
Here is codesandbox
The typescript polymorphic type handing with jackson-js
comes from
https://dev.to/pichillilorenzo/jackson-js-powerful-javascript-decorators-to-serialize-deserialize-objects-into-json-and-vice-versa-part-1-5484
Class Dog
extends class Animal
, and a decorator @JsonSubTypes
on class Animal
uses Dog
.
If I put class Animal
and Dog
in the same file, it works as expected, animal.say()
prints Wang!
to console.
ANSWER
Answered 2021-Dec-30 at 09:54Change the import order from
QUESTION
I have a parent entity that holds a list of child entities. I'm using Spring Data Rest
so there is no custom controller.
These are my entities:
...ANSWER
Answered 2021-Dec-11 at 20:40Turns out, the difference between the two scenarios was not the number of components present in the database but whether there were any changes to the entity. Not sure but seems like JPA is not persisting the entity if there are no changes and probably it does not bother setting these kind of relationships either. There may be a better solution but the workaround is to set the template id in the JSON from the frontend if the entity is not new.
QUESTION
I have a some entities in the database that I'm editing with Spring Data Rest.
All of them have this as a base class:
...ANSWER
Answered 2021-Dec-05 at 09:01It seems to me that you have a bold_font_id
column in your database table, but I can't see any such property in your model classes that map to such a column. Make sure you have a property matching every column in your database table or if not, you will have to assign default values in your database schema while creating it.
QUESTION
I have a simple situation. I have a main DTO class with the following fields: AnimalDTO
...ANSWER
Answered 2021-Nov-25 at 17:09Your code will work just fine (without any @JsonTypeInfo
or @JsonSubTypes
annotations) if the JSON that you get from the external API is as follows:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install JsonSubTypes
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page