Comments (20)
@ibrahim132 try this.
@Parcel(Parcel.Serialization.BEAN)
There won't be any warnings.
from parceler.
A couple of things come to mind:
First, if you want Parceler only to ignore certain fields you can use the Parceler specific @Transient
annotation in leu of the transient
keyword.
Second, not sure if you want this, but if you have getters/setters for your bean's properties, you can use either the Serialization.METHOD
technique or annotate your specific getter/setter methods with @ParcelProperty("secret")
to tell Parceler to use those instead of the private field.
Other than that I could see about adding a @SupressWarnings('parceler')
annotation, but that doesn't exist yet... unless there is a global way to supress warnings with that annotation.
from parceler.
A @SuppressWarnings
annotation would be excellent. If I have to use @Transient
, I'll end up having to enter it about 40 times or more in this codebase, and it makes it rather cluttered and makes reasoning about the code significantly harder than I've already made it making GSON and Parceler play nice together. 😄
from parceler.
I'm a little curious about your gson/parceler model, can you share an example of what you are needing from gson/parcler, particularly around your private data?
To reiterate @Transient
, that annotation tells Parceler to ignore that field for serialization. The result will be that the field is not persisted to a Parcelable or read back from it. A side effect is that Parceler will also not warn you about private accesses.
from parceler.
I misunderstood what @Transient
meant then, because as you've just
described it, it won't work for my case anyway.
I want to be able to suppress the warning about reflection because I've
chosen to use private by design, and accept that reflection is slower but
isn't an issue in my use case.
I could potentially use package level access in my use case but I'd rather
not entice someone to directly access the property if it can be avoided. :-)
On Oct 21, 2014 2:32 AM, "John Ericksen" [email protected] wrote:
I'm a little curious about your gson/parceler model, can you share an
example of what you are needing from gson/parcler, particularly around your
private data?To reiterate @transient, that annotation tells Parceler to ignore that
field for serialization. The result will be that the field is not persisted
to a Parcelable or read back from it. A side effect is that Parceler will
also not warn you about private accesses.—
Reply to this email directly or view it on GitHub
#45 (comment).
from parceler.
Ok, for these private fields, do you have non-private getters and/or setters?
from parceler.
Hmm, yes, and I think I see what you're getting at.
I think my confusion comes from the fact that I have some static classes within a class that are only meant to be used within the context of that outer class, and as such have private
access, and no getters or setters.
Unless I am understanding incorrectly, applying @Parcel(Serialization.METHOD)
to those inner classes, even though they have no getters or setters, should be enough to solve my warnings, and presumably also optimise the parceling?
Also, thank you for patiently talking through this with me. 😄
Here's a gist of one of the classes that was spitting errors, but isn't now that I've applied the annotations as suggested. I'm yet to test to see what happens.
from parceler.
I've since had time to test the implications of Serialization.METHOD
without adding any other attributes, and it doesn't work for me unfortunately. 😞
Once added to an intent with .putExtra(Parcels.wrap(foo))
, .getMode()
returns null when the service receives it from startService
.
Perhaps it is because there are only getters and no setters? The objects are meant to be immutable you see, hence the builder pattern demonstrated in the gist.
from parceler.
Thought I'd share that you can mute annotaion processor (Parceler) warnings via -Xlint:-processing.
http://stackoverflow.com/questions/26410667/suppresswarnings-from-a-java-annotation-processor
from parceler.
@bbqsrc, I think I'm not going to move forward with the @SuppressWarnings
feature since there is a feature to suppress warnings from an annotation processor.
As always, let me know if you need anything else.
from parceler.
Please provide an example for how i can use @ParcelProperty(String value) when i have private filed
from parceler.
@Parcel
public class PrivateFieldExample{
@ParcelProperty("value")
private String exampleValue;
}
from parceler.
Thank you for speed response, But i'm still have warnings.
My class:
@parcel
public class AboutUs {
@SerializedName(APIConstants.ABOUT_US_AR)
@ParcelProperty(APIConstants.ABOUT_US_AR)
private String aboutUsAr;
@SerializedName(APIConstants.ABOUT_US_EN)
@ParcelProperty(APIConstants.ABOUT_US_EN)
private String aboutUsEn;
public AboutUs() {
}
public String getAboutUsAr() {
return aboutUsAr;
}
public void setAboutUsAr(String aboutUsAr) {
this.aboutUsAr = aboutUsAr;
}
public String getAboutUsEn() {
return aboutUsEn;
}
public void setAboutUsEn(String aboutUsEn) {
this.aboutUsEn = aboutUsEn;
}
public String getAboutUs() {
return AppSettings.getInstance(EBIApplication.getInstance())
.getCurrentLanguage()
.equals(AppConstants.ARABIC_LANGUAGE_CODE) ?
getAboutUsAr() : getAboutUsEn();
}
}
Warning:(22, 20) Parceler: Reflection is required to modify private field: String aboutUsAr, consider using non-private.
Warning:(26, 20) Parceler: Reflection is required to modify private field: String aboutUsEn, consider using non-private.
Warning:(22, 20) Parceler: Reflection is required to access private field: String aboutUsAr, consider using non-private.
Warning:(26, 20) Parceler: Reflection is required to access private field: String aboutUsEn, consider using non-private.
from parceler.
Oh, that's not what you were asking...
I'd seriously consider making your fields non-private as this will significantly slow down marshaling. If you can't and you find the warnings annoying, you could add the -Xlint:-processing
option as suggested above.
from parceler.
Sorry, i thought that was for warnings.
I will try to use the Xlint:-processing
Thank you.
from parceler.
@johncarl81 I am still not clear about how to ignore this warning. I tried @SuppressWarnings("parceler")
but still getting warning. I am using parceler version 1.1.9
even ParcelProperty("isChecked") is still giving me warning.
private boolean isChecked;
Warning:(14, 21) Parceler: Reflection is required to access private field: boolean isChecked, consider using non-private.
from parceler.
How to avoid warnings for Singleton classes were the constructor is private. Please help.
from parceler.
You could use a factory method, I guess.
from parceler.
FYI, Serializing and deserializing a "singleton" will mean it has a copy, and thus not a Singleton anymore.
from parceler.
Yeah, I was just looking a way to avoid the warnings. Thanks, @johncarl81.
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.