Comments (4)
If you notice near the end of the stack trace, the last 'Caused by:' entry, it says a NullPointerException occurred. It occurred inside the ObservableListWrapper.size() method. Taking a look at that method, you will see that all it does is call backingList.size(). The backingList member variable is obviously null, and calling size() on it causes the NPE.
This happens because during instantiation of the ObservableListWrapper, the backingList member variable is not getting set. json-io allows you to assign your own 'instantiator' class for situations like this. Use the JsonReader.assignInstantiator() method to assign your own JsonReader.ClassFactory class to be called when a new instance of ObservableListWrapper is needed:
JsonReader.assignInstantiator(ObservableListWrapper.class, myObservableListWrapperCreator);
This will associate a JsonReader.ClassFactory instance to be called which will create the ObservableListWrapper when needed.
public static class MyObservableListWrapperCreator implements JsonReader.ClassFactory
{
Object newInstance(Class c)
{
// properly create an new ObservableListWrapper and return it here
}
}
When the JsonReader encounters an ObservableListWrapper that needs to be created, it will call your factory class to get a new one. Since you are in charge of writing that class, you can properly create a new ObservalListWrapper and return it.
JsonReader does a lot of work to attempt to construct any class it encounters, including calling all constructors, private constructors, even using sun.misc.Unsafe if available. However, some classes still require their constructors to be called. This is why JsonReader has the ability to allow you to install your own 'constructors' as needed.
from json-io.
Ok that is nice, I see now the power of json-io with that feature. I readed twice your explanation and I search in the api but I can't figure how to "properly create an new ObservableListWrapper and return it here", given a Class as parameter. I checked the code of JsonReader's CollectionFactory class and I infered that the naive approach would be something like
public class OberservableListWrapperCreator implements ClassFactory {
@Override
public Object newInstance(Class c) {
if(ObservableListWrapper.class.isAssignableFrom(c))
return new ObservableListWrapper(null);
else
throw new JsonIoException("CollectionFactory handed Class for which it was not expecting: " + c.getName());
}
}
But obviously isn't. Sorry for my skills, can you tell me more about how I have to implement that? Thanks a lot
from json-io.
First, you do not need an 'isAssignableFrom()' check. Your code will only be
called with a ObservableListWrapper.class. Pass whatever you need to
your ObservableListWrapperCreator in it's constructor that you would need
to create the class properly. Currently, your class does not have any constructor, so your 'newInstance(Class c)' method has no 'help' to create the class.
I am not familiar with this particular (ObservableListWrapper) class, but I am sure there is a
'normal' way to create an instance of ObservableListWrapper. Create the
instance in this method this 'normal' way [look at the JDK code if necessary], and then return it. If you need some external instances, those can be passed through your [missing] constructor, and then
used in the newInstance() method.
On Sun, Jun 21, 2015 at 7:18 PM, Otto [email protected] wrote:
Ok that is nice, I see now the power of json-io with that feature. I
readed twice your explanation and I search in the api but I can't figure
how to "properly create an new ObservableListWrapper and return it here",
given a Class as parameter. I checked the code of JsonReader's
CollectionFactory class and I infered that the naive approach would be
something likepublic class OberservableListWrapperCreator implements ClassFactory {
@Override public Object newInstance(Class c) { if(ObservableListWrapper.class.isAssignableFrom(c)) return new ObservableListWrapper(null); else throw new JsonIoException("CollectionFactory handed Class for which it was not expecting: " + c.getName()); }
}
But obviously isn't. Sorry for my skills, can you tell me more about how I
have to implement that? Thanks a lot—
Reply to this email directly or view it on GitHub
#42 (comment).
from json-io.
Thank you a lot, I just did it.
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.