Comments (12)
Parceler actually doesn't support Object as it is not a type represented within the Parcel (yes, there is the writeValue(Object)
method, but internally it does an instanceof
to determine what type to write).
It seems like your last example should work. I wonder if the ParcelClass
converter parameter is not being picked up. I'll look into this.
from parceler.
Found a couple of bugs with the approach, but I found one that worked. Try this:
@Parcel
public class ParcelableObject {
@ParcelProperty("test")
@ParcelPropertyConverter(ParcelableInnerIntegerConverter.class)
ParcelableInner<Integer> parcelableInner;
public static class ParcelableInner<T> {
T i;
}
public static class ParcelableInnerIntegerConverter implements ParcelConverter<ParcelableInner<Integer>> {
@Override
public void toParcel(ParcelableInner<Integer> input, android.os.Parcel parcel) {
}
@Override
public ParcelableInner<Integer> fromParcel(android.os.Parcel parcel) {
return null;
}
}
}
Currently Parceler doesn't allow you to annotate a field with @ParcelPropertyConverter
without an accompanying @ParcelProperty
annotation. I will be pushing out a fix for this shortly.
from parceler.
Thanks for your answer, your example works but it's a bit verbose, two annotations every time you need to use the inner class.
Another working solution is this:
@Parcel
@ParcelClass(value = ParcelableObject.ParcelableInner.class, converter = ParcelableObject.ParcelableInnerIntegerConverter.class)
public class ParcelableObject {
ParcelableInner parcelableInner;
public static class ParcelableInner<T> {
@Transient
T i;
}
public static class ParcelableInnerIntegerConverter implements ParcelConverter<ParcelableInner<Integer>> {
@Override
public void toParcel(ParcelableInner<Integer> input, android.os.Parcel parcel) {
}
@Override
public ParcelableInner<Integer> fromParcel(android.os.Parcel parcel) {
return null;
}
}
}
But I don't like it because the field ParcelableInner is not defined as a generic (it should be ParcelableInner. Is this a bug that you already fixed?
from parceler.
Yes, @fabioCollini, I fixed the requirement to have a @ParcelProperty
with a @ParcelPropertyConverter
(909b4ab). This should work with 0.2.14-SNAPSHOT:
@Parcel
public class ParcelableObject {
@ParcelPropertyConverter(ParcelableInnerIntegerConverter.class)
ParcelableInner<Integer> parcelableInner;
public static class ParcelableInner<T> {
T i;
}
public static class ParcelableInnerIntegerConverter implements ParcelConverter<ParcelableInner<Integer>> {
@Override
public void toParcel(ParcelableInner<Integer> input, android.os.Parcel parcel) {
}
@Override
public ParcelableInner<Integer> fromParcel(android.os.Parcel parcel) {
return null;
}
}
}
Give it a try and please let me know if it works for you.
from parceler.
Now using ParcelPropertyConverter it works correctly but there is still an error using ParcelClass:
@Parcel
@ParcelClass(value = ParcelableObject.ParcelableInner.class, converter = ParcelableObject.ParcelableInnerIntegerConverter.class)
public class ParcelableObject {
ParcelableInner<Integer> parcelableInner;
public static class ParcelableInner<T> {
T i;
}
public static class ParcelableInnerIntegerConverter implements ParcelConverter<ParcelableInner<Integer>> {
@Override
public void toParcel(ParcelableInner<Integer> input, android.os.Parcel parcel) {
}
@Override
public ParcelableInner<Integer> fromParcel(android.os.Parcel parcel) {
return null;
}
}
}
Exception in thread "pool-556-thread-1" org.parceler.ParcelerRuntimeException: Unable to find appropriate Parcel method to write it.cosenonjaviste.ParcelableObject.ParcelableInner
Could you fix this example too?
Thanks again!
from parceler.
That example is unfortunately not going to work with some limitations of annotations. Parceler does a deep equality between classes, thus:
ParcelableInner.class != ParcelableInner<Integer>.class
This would work if we could define the annotation like so:
@ParcelClass(value = ParcelableObject.ParcelableInner<Integer>.class, converter = ParcelableObject.ParcelableInnerIntegerConverter.class)
For instance, this should work (with the latest SNAPSHOT... I had to fix a bug related to this):
@Parcel
@ParcelClass(value = ParcelableObject.ParcelableInnerInteger.class, converter = ParcelableObject.ParcelableInnerIntegerConverter.class)
public class ParcelableObject {
ParcelableInnerInteger parcelableInner;
public static class ParcelableInnerInteger extends ParcelableInner<Integer>{}
public static class ParcelableInner<T> {
T i;
}
public static class ParcelableInnerIntegerConverter implements ParcelConverter<ParcelableInnerInteger> {
@Override
public void toParcel(ParcelableInnerInteger input, android.os.Parcel parcel) {
}
@Override
public ParcelableInnerInteger fromParcel(android.os.Parcel parcel) {
return null;
}
}
}
from parceler.
Are you sure? Executing Parcels.wrap(new ParcelableObject.ParcelableInner()) works, Parcels.REPOSITORY contains the right data. Why don't you just ignore generics when a field is defined using generic types?
from parceler.
@fabioCollini, can you clarify? How did you annotate your ParcelableInner
class?
from parceler.
This is an example where I am using it, this is the generic class:
This is the converter:
I am using it in this class (removing the generic works):
Another attempt is to extends the class:
It works but it uses it as a serializable object instead of the converter (maybe is this a bug?).
And a question: is there a guide to configure parceler workspace?
from parceler.
Using a Serializable
object is not ideal, but if it's the only way to transfer your Throwable
you may be out of luck. Could you annotate your Throwable
with @Parcel
?
What sort of guide are you looking for? I was thinking about putting together a proper website. Currently the github README is the best place for documentation.
from parceler.
You are right about the throwable, but I defined a converter for the base class. I am extending this class but it write the field of the base class in the parcel as a serializable (the converter on the base class is ignored).
from parceler.
Looks like everything is in order... you good to close or did we not address this?
from parceler.
Related Issues (20)
- Ability to treat reflection warnings as errors HOT 5
- Parceler fails when used with with Lifecycle-viewmodel 2.2.0 HOT 7
- Facing Vulnerabilities in parceler library HOT 1
- Facing Vulnerabilities in parceler library HOT 1
- Polymorphism documentation not updated? HOT 6
- Cannot get working with navigation graph HOT 1
- Crashing on background HOT 4
- ParcelAnnotationProcessor.process take lot amount of time. HOT 15
- Unable to find generated Parcelable class HOT 1
- error: Parceler: Code generation did not complete successfully. HOT 47
- Cant find class to parcel ! HOT 1
- Can't generate code HOT 3
- Unable to Marshall with Parceler HOT 2
- Errors in HashMap$$PackageHelper HOT 3
- cannot running with kapt HOT 1
- Parceler: Code generation did not complete successfully. org.parceler.transfuse.transaction.TransactionRuntimeException: Encountered ErrorType <error>, unable to recover HOT 4
- [Request Feature] Support for Kotlin Symbol Processing
- Parceler code generation fails on AS 2023.3.1
- Getters and Setter Alphabetically Order for Write and Read
- Not sure how to convert a Cursor
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 parceler.