如何创建一个parcelable pojo类

时间:2012-02-24 12:37:37

标签: android pojo

我一直坚持创造pojo课程。

我的服务器响应是

<items>
   <dining>
       <item>
          <itemID>8528</itemID>
          <enabled>true</enabled>
          <modified>false</modified>
          <type>DINING</type>
          <title>Boca at The Conga Room</title>
       </item>
   </dining>
   <server>abc</server>
</items>

帮帮我。下面是我的班级。

@Root(name = "items", strict = false)
public class DiningBucket {

@Element(name = "dining", required = false)
public Dining dining;

public Dining getDining() {
    return dining;
}

public void setDining(Dining dining) {
    this.dining = dining;
}

@Element(name = "ServerTime")
private String serverTime;

/*public ArrayList<Promotions> getPromotions() {
    return dining;
}*/

/*public void setImages(ArrayList<Promotions> promotions) {
    this.dining = promotions;
}*/

public String getServerTime() {
    return serverTime;
}

public void setServerTime(String serverTime) {
    this.serverTime = serverTime;
}


@Root(name = "item", strict = false)
public static class Item {
    // Column names for the database table
            public static final String _ITEMID = "itemID";
            public static final String TITLE = "title";
            public static final String DESCRIPTION = "description";
            public static final String TEXT = "text";
            public static final String EXTERNAL_LINK_URL =    "external_link_url";
            public static final String IMAGE_URL = "image_url";
            public static final String THUMBNAIL_URL = "thumbnail_url";
            public static final String SEQUENCE_NUM = "sequence_num";
            //public static final String CFID = "cfid";

            public static final String[] ALL_COLUMNS = new String[] { _ITEMID, TITLE,
                DESCRIPTION, TEXT, EXTERNAL_LINK_URL, IMAGE_URL, THUMBNAIL_URL,
                SEQUENCE_NUM};

            @Element(name = "itemID", required=false)
            private String id;

            @Element(name="enabled" , required = false)
            private boolean enabled;

            @Element(name = "title", required=false)
            private String title;

            @Element(name = "description", required = false)
            private String description;

            @Element(name = "text", required = false)
            private String text;

            @Element(name = "externalUrl", required = false)
            private String externalLinkUrl = "";

            @Element(name = "contentUrl", required = false)
            private String imageUrl;

            @Element(name = "contentAltUrl", required = false)
            private String thumbnailUrl;

            @Element(name = "sequenceNumber", required = false)
            private String sequenceNum;

        /*  public static Item fromCursor(Cursor c) {
                if (c == null) {
                    return null;
                }
                Item item = new Item();
                item.setId(Integer.toString(c.getInt(c
                        .getColumnIndexOrThrow(_ITEMID))));
                item.setTitle(c.getString(c.getColumnIndexOrThrow(TITLE)));
                item.setDescription(c.getString(c
                        .getColumnIndexOrThrow(DESCRIPTION)));
                item.setLinkUrl(c.getString(c
                        .getColumnIndexOrThrow(EXTERNAL_LINK_URL)));
                item.setImageUrl(c.getString(c
                        .getColumnIndexOrThrow(IMAGE_URL)));
                item.setThumbnailUrl(c.getString(c
                        .getColumnIndexOrThrow(THUMBNAIL_URL)));
                item.setSequenceNum(c.getString(c
                        .getColumnIndexOrThrow(SEQUENCE_NUM)));
                // promotion.setDescription(c.getString(c.getColumnIndexOrThrow(TEXT)));
                // promotions.setCfid(c.getString(c.getColumnIndexOrThrow(CFID)));

                return item;
            }

* /
                public String getId(){                     返回id;                 }

            public void setId(String id) {
                this.id = id;
            }

            public boolean isEnabled() {
                return enabled;
            }

            public void setEnabled(boolean enabled) {
                this.enabled = enabled;
            }

            public String getTitle() {
                return title;
            }

            public void setTitle(String title) {
                this.title = title;
            }

            public String getLinkUrl() {
                return externalLinkUrl;
            }

            public void setLinkUrl(String linkUrl) {
                this.externalLinkUrl = linkUrl;
            }

            public String getExternalLinkUrl() {
                return externalLinkUrl;
            }

            public void setExternalLinkUrl(String externalLinkUrl) {
                this.externalLinkUrl = externalLinkUrl;
            }

            public String getImageUrl() {
                return imageUrl;
            }

            public void setImageUrl(String imageUrl) {
                this.imageUrl = imageUrl;
            }

            public String getThumbnailUrl() {
                return thumbnailUrl;
            }

            public void setThumbnailUrl(String thumbnailUrl) {
                this.thumbnailUrl = thumbnailUrl;
            }

            public String getSequenceNum() {
                return sequenceNum;
            }

            public void setSequenceNum(String sequenceNum) {
                this.sequenceNum = sequenceNum;
            }

            /*public String getCfid() {
                return cfid;
            }

            public void setCfid(String cfid) {
                this.cfid = cfid;
            }*/

            public String getDescription() {
                return description;
            }

            public void setDescription(String description) {
                this.description = description;
            }

            public String getText() {
                return text;
            }

            @Override
             public String toString() {
                return "Dining [id=" + id + ", enabled=" + enabled + ", title="
                        + title + ", description=" + description + ", text=" + text
                        + ", externalLinkUrl=" + externalLinkUrl + ", imageUrl="
                        + imageUrl + ", thumbnailUrl=" + thumbnailUrl
                        + ", sequenceNum=" + sequenceNum + "]";
            }


}


public static class Dining {
    @ElementList(name = "item")
    private ArrayList<Item> item;

    public ArrayList<Item> getItem() {
        return item;
    }

    public void setItem(ArrayList<Item> item) {
        this.item = item;
    }
}

这是我的pojo课程。我得到了这个例外。

org.simpleframework.xml.core.PersistenceException:元素'item'在第-1行声明两次

1 个答案:

答案 0 :(得分:0)

为什么不将可序列化接口添加到模型的类中?