bluelinelabs / LoganSquare

Screaming fast JSON parsing and serialization library for Android.
Apache License 2.0
3.21k stars 306 forks source link

Can't serialize an array #189

Open KimiChiu opened 7 years ago

KimiChiu commented 7 years ago
apt 'com.bluelinelabs:logansquare-compiler:1.3.6'
compile 'com.bluelinelabs:logansquare:1.3.6'
@JsonObject
public class AnsiFont implements Serializable {

    private static final long serialVersionUID = 1L;

    @JsonField
    private String foregroundColor;

    @JsonField
    private String backgroundColor;

    @JsonField
    private boolean underline = false;

    @JsonField
    private boolean hyperLink = false;

    public String getForegroundColor() {
        return foregroundColor;
    }

    public void setForegroundColor(String foregroundColor) {
        this.foregroundColor = foregroundColor;
    }

    public String getBackgroundColor() {
        return backgroundColor;
    }

    public void setBackgroundColor(String backgroundColor) {
        this.backgroundColor = backgroundColor;
    }

    public boolean isUnderline() {
        return underline;
    }

    public void setUnderline(boolean underline) {
        this.underline = underline;
    }

    public boolean isHyperLink() {
        return hyperLink;
    }

    public void setHyperLink(boolean hyperLink) {
        this.hyperLink = hyperLink;
    }

    public AnsiFont clone(){
        return AnsiFont.Builder.anAnsiFont()
                .withForegroundColor( foregroundColor )
                .withBackgroundColor( backgroundColor )
                .withHyperLink( hyperLink )
                .withUnderline( underline )
                .build();
    }

    public static class Builder {
        private String foregroundColor;
        private String backgroundColor;
        private boolean underline = false;
        private boolean hyperLink = false;

        private Builder() {
        }

        public static Builder anAnsiFont() {
            return new Builder();
        }

        public Builder withForegroundColor(String foregroundColor) {
            this.foregroundColor = foregroundColor;
            return this;
        }

        public Builder withBackgroundColor(String backgroundColor) {
            this.backgroundColor = backgroundColor;
            return this;
        }

        public Builder withUnderline(boolean underline) {
            this.underline = underline;
            return this;
        }

        public Builder withHyperLink(boolean hyperLink) {
            this.hyperLink = hyperLink;
            return this;
        }

        public Builder but() {
            return anAnsiFont().withForegroundColor(foregroundColor).withBackgroundColor(backgroundColor).withUnderline(underline).withHyperLink(hyperLink);
        }

        public AnsiFont build() {
            AnsiFont ansiFont = new AnsiFont();
            ansiFont.setForegroundColor(foregroundColor);
            ansiFont.setBackgroundColor(backgroundColor);
            ansiFont.setUnderline(underline);
            ansiFont.setHyperLink(hyperLink);
            return ansiFont;
        }
    }
}
AnsiFont[][] fonts = new AnsiFont[30][30];
// NoSuchMapperException
LoganSquare.serialize(fonts);
// NoSuchMapperException
LoganSquare.serialize(fonts[0]);
// Success
LoganSquare.serialize(fonts[0][0]);

Any ideas?