RoboSpice persist JSON array with OrmLite

前端 未结 3 1439

I\'m using RoboSpice with Spring for Android and would like to persist a JSON array of objects with OrmLite. GSON is used for the JSON marshalling. With the default caching

3条回答
  •  忘掉有多难
    2021-01-13 09:25

    I have found the way which works for me. I did not changed my json.

    @DatabaseTable(tableName = SampleContract.Contributor.TABLE)
    public class Contributor {
    
        @DatabaseField(generatedId = true, columnName = SampleContract.Contributor._ID)
        private int id;
    
        @DatabaseField(columnName = SampleContract.Contributor.LOGIN)
        public String login;
    
        @DatabaseField(columnName = SampleContract.Contributor.CONTRIBUTIONS)
        public int contributions;
    
        @DatabaseField(foreign = true)
        private ContributorsResult result;
    
        @SuppressWarnings("serial")
        @DatabaseTable(tableName = "contributor_list")
        public static class ContributorsResult extends ArrayList {
    
            @DatabaseField(id = true)
            private int id = 0;
    
    
            @ForeignCollectionField(eager = false)
            private Collection result = this;
    
            public Collection getResult() {
                return result;
            }
    
            public void setResult(Collection result) {
                if (result != null) {
                    this.clear();
                    this.addAll(result);
                }
            }
    
        }
    
    
    }
    

提交回复
热议问题