Comments (10)
Hey @joaofyz, if the API does not make a type
difference between Car
and Vehicle
than your model should not do it.
What you can do is the following:
- have one class that has all the attributes
- create a factory that will create specific subclass depending on the attributes
Now I understand that these are design choices that you made for a reason, sadly it is not possible to create different object having same type
attribute.
from jsonapi-converter.
Hello,
This is not related to the JSONAPI spec but rather to jackson library.
http://wiki.fasterxml.com/JacksonPolymorphicDeserialization
Regards
from jsonapi-converter.
Thanks jasminb for your answer.
I was able to solve my problem with the @JsonTypeInfo and @JsonSubTypes annotations.
The only issue I identified was the need to have always de @id annotation and field in every class even if it already exists in the Super class.
from jsonapi-converter.
Hey,
I've pushed a change today that solves the inheritance issue you are referring to.
If you use SNAPSHOT version of the library, it will work with inherited @id field.
Regards
from jsonapi-converter.
I do not use the SNAPSHOT version but I think you can close this issue.
Thanks for your help
from jsonapi-converter.
Hi,
I'm having another problem with the hierarchical classes, now serializing the objects.
All my objects in JSONAPI are from the same type @type("object_type"), but I can not have the same @type annotation in the main and child classes. How can I do this?
Thanks
from jsonapi-converter.
Hey @joaofyz,
You cant inherit type (have multiple classes of the same type), however you can have a base class that has most of your attributes and than extend it and specify the type and additional attributes that you need.
When you deserialise you can do the following:
MyBaseClass object = resourceConverter.readDocument(data, MyBaseClass.class);
object
will be instance of the correct subtype depending on the type
attribute present in the data
.
As for serialisation, no problem there, just writeDocument
as usual.
from jsonapi-converter.
I don't think this will solve my issue. Let me try to explain what I want to archive:
What I have now is the following:
One class Vehicle
@Type("vehicle") public class Vehicle { ... }
And a subclass Car
@Type("car") public class Car { ... }
I would like to have the @type("vehicle") in the car also.
Thanks for the help again ;)
from jsonapi-converter.
Can you give more background on why would you want to have same type on multiple classes?
from jsonapi-converter.
Hi @jasminb
In the business prespective they are all "vehicles", so they are all mapped has vehicles.
Do you think I will be able to do this?
from jsonapi-converter.
Related Issues (20)
- How to generate this nested JSON (tenor) ? HOT 1
- Should ALLOW_UNKNOWN_TYPE_IN_RELATIONSHIP be less restrictive HOT 7
- @Id obfuscated by proguard even after excluding the annotation HOT 2
- POST Example with RestTemplate HOT 2
- How to configure ObjectMapper? HOT 2
- @Type serialization HOT 2
- Document collection always throw error while using readCollections HOT 1
- Object with relations itself HOT 1
- @Relationship is not being deserialized HOT 2
- Creating a resource on the server - required id field HOT 2
- Does the library support Javas webclient and the reactor implementation? HOT 2
- "jsonapi": { "version": "1.0" } Parser HOT 2
- Get value above "attributes" level HOT 2
- Relationship attributes dont serialized HOT 3
- The library does not support JSON Specification "8.3 Inclusion of Related Resources" HOT 13
- Class doesn't have a Type annotation error, even though the class does have one HOT 3
- Proguard issues with jsonapi-converter when Android project to targets java 17 HOT 2
- InvalidJsonApiResourceException: Resource must contain at least one of 'data', 'error' or 'meta' nodes
- Handling local identifier ("lid") when creating resource HOT 4
- Backward compatibility HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsonapi-converter.