Comments (4)
I see a couple of issues with what is listed here. First, the field type
cannot be "morphed" unless you are using both a custom reader and a custom
writer. Are you doing that? If not, the reader will blow up when it
encounters the String and tries to 'set' it into the field of type
'WordProcessorMainWindowSpan'.
Second, overriding CharSequence is asking for trouble, as that would also
override String, for which is handled specially by json-io. Was
CharSequence just an example? If so, could you provide a different
example? I am still not sure I understand what exactly is the issue.
On Mon, Jul 7, 2014 at 6:20 PM, LXE [email protected] wrote:
Use case:
- field type is an interface type (e.g. CharSequence);
- I don't want to preserve the concrete class of the value (it can be
complicated and heavyweight, something like WordProcessorMainWindowSpan);- I inherit a custom writer from JsonStringWriter and write
value.toString() as a primitive String;- I call addWriter(CharSequence.class, myCustomWriter). Expected:
- value is serialized and retrieved as String; Actual:
- writer is not recognized because no superclass matches CharSequence.
P.S. For interfaces, I'd also appreciate the ability to stick to a default
implementation explicitly (i.e. override the concrete type upon
deserialization - of course, within types assignable to the declared field
type).—
Reply to this email directly or view it on GitHub
#12.
from json-io.
- Yes, I am using a custom reader and a custom writer. (Or at least "I can do it if I have to".)
- No, I do not want to "morph" the field type. I want to "morph" the concrete value type. Have you got the difference?
- Overriding CharSequence will not override String because of getDistance(classA, classB). Distance between String and String is zero, so the default reader/writer would be used for the concrete type String.
- I think my example explains the issue well enough. I will stick to it.
from json-io.
To summarize, if the object graph is
class POJO {
CharSequence data;
}
I want to ensure the following postcondition:
((POJO) JsonReader.jsonToJava(whatever)).data instanceof String
no matter what the concrete type of data was before calling javaToJson(originalPojo).
from json-io.
So far I went without it by doing the conversion (.toString()) in the field setter - but that's not as efficient as it could be (the setter could have been called many times before the actual serialization).
from json-io.
Related Issues (20)
- vulnerable to Denial Of Services (DoS) HOT 2
- Exception while deserializing `SingletonList` HOT 1
- Incorrect looking tag "14.4.2" for release version 4.14.2 HOT 1
- Possible issue about list of objects that have custom writers HOT 5
- Java class version 55 for 4.14.2 HOT 3
- Revisiting issue 17 HOT 6
- Enums are serialized differently with 4.15.0 HOT 3
- 4.15 --> 4.16 default mapping method fails to parse HOT 7
- Enhance the robustness of tests
- ReadOptionsBuilder HOT 1
- Compile / runtime dependency on com.novell.ldap:jldap HOT 3
- How to deserialise javafx classes with inaccessible fields? HOT 2
- Request for tutorial HOT 2
- NoSuchMethodError after upgrade HOT 24
- Custom serialising of objects with inheritance HOT 2
- Encoding Bug for JsonIo.toJson("🙊🙉🙈", null)? HOT 3
- Custom Writers not including id and ref in output? HOT 3
- Compatibility between 4.14.0 and 4.20.0 HOT 4
- User guide Untyped Usage HOT 1
- high usage of metaspace after upgrade to 4.22.0 HOT 4
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 json-io.