Giter VIP home page Giter VIP logo

Comments (20)

Aks-4125 avatar Aks-4125 commented on May 22, 2024 1

@ibrahim132 try this.

@Parcel(Parcel.Serialization.BEAN)

There won't be any warnings.

from parceler.

johncarl81 avatar johncarl81 commented on May 22, 2024

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.

bbqsrc avatar bbqsrc commented on May 22, 2024

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.

johncarl81 avatar johncarl81 commented on May 22, 2024

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.

bbqsrc avatar bbqsrc commented on May 22, 2024

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.

johncarl81 avatar johncarl81 commented on May 22, 2024

Ok, for these private fields, do you have non-private getters and/or setters?

from parceler.

bbqsrc avatar bbqsrc commented on May 22, 2024

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.

bbqsrc avatar bbqsrc commented on May 22, 2024

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.

johncarl81 avatar johncarl81 commented on May 22, 2024

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.

johncarl81 avatar johncarl81 commented on May 22, 2024

@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.

IbrahimDisouki avatar IbrahimDisouki commented on May 22, 2024

Please provide an example for how i can use @ParcelProperty(String value) when i have private filed

from parceler.

johncarl81 avatar johncarl81 commented on May 22, 2024

@ibrahim132:

@Parcel
public class PrivateFieldExample{
    @ParcelProperty("value")
    private String exampleValue;
}

from parceler.

IbrahimDisouki avatar IbrahimDisouki commented on May 22, 2024

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.

johncarl81 avatar johncarl81 commented on May 22, 2024

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.

IbrahimDisouki avatar IbrahimDisouki commented on May 22, 2024

Sorry, i thought that was for warnings.
I will try to use the Xlint:-processing
Thank you.

from parceler.

Aks-4125 avatar Aks-4125 commented on May 22, 2024

@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.

aniketmane avatar aniketmane commented on May 22, 2024

How to avoid warnings for Singleton classes were the constructor is private. Please help.

from parceler.

johncarl81 avatar johncarl81 commented on May 22, 2024

You could use a factory method, I guess.

from parceler.

johncarl81 avatar johncarl81 commented on May 22, 2024

FYI, Serializing and deserializing a "singleton" will mean it has a copy, and thus not a Singleton anymore.

from parceler.

aniketmane avatar aniketmane commented on May 22, 2024

Yeah, I was just looking a way to avoid the warnings. Thanks, @johncarl81.

from parceler.

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.