Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Model using jackson #8810

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/anki/AnkiSerialization.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
*/
package com.ichi2.anki;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -35,6 +38,9 @@ private AnkiSerialization(){}
public static ObjectMapper getObjectMapper() {
if (objectMapper == null) {
objectMapper = new ObjectMapper()
.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE)
.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY)
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
return objectMapper;
Expand Down
136 changes: 136 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/libanki/json/model/Field.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@

package com.ichi2.libanki.json.model;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class Field {

@JsonProperty("name")
private String mName;

@JsonProperty("ord")
private Long mOrdinal;

@JsonProperty("sticky")
private Boolean mSticky;

@JsonProperty("rtl")
private Boolean mRtl;

@JsonProperty("font")
private String mFont;

@JsonProperty("size")
private Long mSize;

@JsonProperty("media")
private List<Object> mMedia;

@JsonProperty("single line")
private Boolean mSingleLine;

@JsonIgnore
private final Map<String, Object> mAdditionalProperties = new HashMap<>();


/**
* No args constructor for use in serialization
*/
public Field() {
}

public Field(String name, Long ord, Boolean sticky, Boolean rtl, String font, Long size, List<Object> media, Boolean singleLine) {
super();
this.mName = name;
this.mOrdinal = ord;
this.mSticky = sticky;
this.mRtl = rtl;
this.mFont = font;
this.mSize = size;
this.mMedia = media;
this.mSingleLine = singleLine;
}

public String getName() {
return mName;
}

public void setName(String name) {
this.mName = name;
}

public Long getOrdinal() {
return mOrdinal;
}

public void setOrdinal(Long ordinal) {
this.mOrdinal = ordinal;
}

public Boolean isSticky() {
return mSticky;
}

public void setSticky(Boolean sticky) {
this.mSticky = sticky;
}

public Boolean isRtl() {
return mRtl;
}

public void setRtl(Boolean rtl) {
this.mRtl = rtl;
}

public String getFont() {
return mFont;
}

public void setFont(String font) {
this.mFont = font;
}

public Long getSize() {
return mSize;
}

public void setSize(Long size) {
this.mSize = size;
}

public List<Object> getMedia() {
return mMedia;
}

public void setMedia(List<Object> media) {
this.mMedia = media;
}

public Boolean isSingleLine() {
return mSingleLine;
}

public void setSingleLine(Boolean singleLine) {
this.mSingleLine = singleLine;
}

@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return this.mAdditionalProperties;
}

@JsonAnySetter
public void setAdditionalProperty(String name, Object value) {
this.mAdditionalProperties.put(name, value);
}

}
208 changes: 208 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/libanki/json/model/Model.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@

package com.ichi2.libanki.json.model;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;


public class Model {

@JsonProperty("id")
private Long mId;

@JsonProperty("name")
private String mName;

@JsonProperty("type")
private ModelType mType;

@JsonProperty("mod")
private Long mMod;

@JsonProperty("usn")
private Long mUsn;

@JsonProperty("sortf")
private Long mSortingField;

@JsonProperty("did")
private Long mDeckId;

@JsonProperty("tmpls")
private List<Template> mTemplates;

@JsonProperty("flds")
private List<Field> mFields;

@JsonProperty("css")
private String mCss;

@JsonProperty("latexPre")
private String mLatexPrefix;

@JsonProperty("latexPost")
private String mLatexPostfix;

@JsonProperty("latexsvg")
private Boolean mLatexSvg;

@JsonProperty("req")
private List<Requirement> mRequirements;

@JsonIgnore
private final Map<String, Object> mAdditionalProperties = new HashMap<>();

/**
* No args constructor for use in serialization
*
*/
public Model() {
}


public Model(Long id, String name, ModelType type, Long mod, Long usn, Long sortf, Long did, List<Template> tmpls, List<Field> flds, String css, String latexPre, String latexPost, Boolean latexsvg, List<Requirement> req) {
super();
this.mId = id;
this.mName = name;
this.mType = type;
this.mMod = mod;
this.mUsn = usn;
this.mSortingField = sortf;
this.mDeckId = did;
this.mTemplates = tmpls;
this.mFields = flds;
this.mCss = css;
this.mLatexPrefix = latexPre;
this.mLatexPostfix = latexPost;
this.mLatexSvg = latexsvg;
this.mRequirements = req;
}

public Long getId() {
return mId;
}

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

public String getName() {
return mName;
}

public void setName(String name) {
this.mName = name;
}

public ModelType getType() {
return mType;
}

public void setType(ModelType type) {
this.mType = type;
}

public Long getMod() {
return mMod;
}

public void setMod(Long mod) {
this.mMod = mod;
}

public Long getUsn() {
return mUsn;
}

public void setUsn(Long usn) {
this.mUsn = usn;
}

public Long getSortingField() {
return mSortingField;
}

public void setSortingField(Long sortingField) {
this.mSortingField = sortingField;
}

public Long getDeckId() {
return mDeckId;
}

public void setDeckId(Long deckId) {
this.mDeckId = deckId;
}

public List<Template> getTemplates() {
return mTemplates;
}

public void setTemplates(List<Template> templates) {
this.mTemplates = templates;
}

public List<Field> getFields() {
return mFields;
}

public void setFields(List<Field> fields) {
this.mFields = fields;
}

public String getCss() {
return mCss;
}

public void setCss(String css) {
this.mCss = css;
}

public String getLatexPrefix() {
return mLatexPrefix;
}

public void setLatexPrefix(String latexPrefix) {
this.mLatexPrefix = latexPrefix;
}

public String getLatexPostfix() {
return mLatexPostfix;
}

public void setLatexPostfix(String latexPostfix) {
this.mLatexPostfix = latexPostfix;
}

public Boolean isLatexsvg() {
return mLatexSvg;
}

public void setLatexSvg(Boolean latexSvg) {
this.mLatexSvg = latexSvg;
}

public List<Requirement> getRequirements() {
return mRequirements;
}

public void setRequirements(List<Requirement> requirements) {
this.mRequirements = requirements;
}

@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return this.mAdditionalProperties;
}

@JsonAnySetter
public void setAdditionalProperty(String name, Object value) {
this.mAdditionalProperties.put(name, value);
}

}
Loading