Coder Social home page Coder Social logo

Comments (4)

jdereg avatar jdereg commented on August 26, 2024

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.

treeswift avatar treeswift commented on August 26, 2024
  • 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.

treeswift avatar treeswift commented on August 26, 2024

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.

treeswift avatar treeswift commented on August 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.