@SerializedName annotation for defining Class/Field names
See original GitHub issueWe need something similar to GSON’s SerializedName
annotation which can map a different name field from JSON string to RealmObject’s property.
eg:
{ "dog_name": "abc"}
class Dog {
@SerializedName("dog_name")
private String name;
}
Issue Analytics
- State:
- Created 8 years ago
- Reactions:18
- Comments:34 (16 by maintainers)
Top Results From Across the Web
Gson @SerializedName - Change field names example
Gson @SerializedName is used to change the name of fields between JSON and Java objects while the serialization and deserialization process.
Read more >Multiple GSON @SerializedName per field? - Stack Overflow
Reason: By default Deserialization is managed with a LinkedHashMap and the keys are defined by incoming json's field names (not the custom class's...
Read more >@SerializedName annotation for defining Class/Field names -
We need something similar to GSON's SerializedName annotation which can map a different name field from JSON string to RealmObject's property.
Read more >What to use @SerializedName annotation using Gson in Java?
The @SerializedName annotation can be used to serialize a field with a different name instead of an actual field name.
Read more >How to read and write JSON using Gson in Java
JSON Field Naming with @SerializedName Annotation. By default, Gson uses the class field names as JSON property names.
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 Free
Top 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
I have the same feeling, but it gets a bit tricky, because cross-platform schemas are a big topic for us right now 😄
Thinking about this. Maybe this is actually the best time to actually split our JSON API away from Realm, because a
@SerializedName
for JSON would only make sense if you used our JSON API, if you use e.g GSON it would just be confusing that Realm also had a similar annotation.Instead we should create adapters for the various JSON imports:
Alternatively they get configured through the new
realm
closure block introduced in 2.0It would have the following implications:
createFromJson*
andcreateOrUpdateFromJson*
methods would be removed from our current public API.copyToRealm
, but we need somewhere to hook “standard” JSON output in. Where isn’t clear to me.Split the json to another project would be great, especially we will have a chance to switch to javapoet from there. But the new project probably needs to be more generic to support other data converters than JSON, eg. flatbuffer.