From 5c04bb3f4b6cf19efb28f2f7cf260b4a19ffe9b8 Mon Sep 17 00:00:00 2001 From: Tarekk Mohamed Abdalla Date: Wed, 12 May 2021 16:58:50 +0200 Subject: [PATCH] wip models using jackson --- .../com/ichi2/libanki/json/model/Field.java | 146 +++++ .../com/ichi2/libanki/json/model/Model.java | 269 +++++++++ .../ichi2/libanki/json/model/Requirement.java | 58 ++ .../ichi2/libanki/json/model/Template.java | 157 ++++++ AnkiDroid/src/test/assets/one_model.json | 515 ++++++++++++++++++ .../ichi2/libanki/json/model/ModelTest.java | 71 +++ 6 files changed, 1216 insertions(+) create mode 100755 AnkiDroid/src/main/java/com/ichi2/libanki/json/model/Field.java create mode 100755 AnkiDroid/src/main/java/com/ichi2/libanki/json/model/Model.java create mode 100644 AnkiDroid/src/main/java/com/ichi2/libanki/json/model/Requirement.java create mode 100755 AnkiDroid/src/main/java/com/ichi2/libanki/json/model/Template.java create mode 100644 AnkiDroid/src/test/assets/one_model.json create mode 100644 AnkiDroid/src/test/java/com/ichi2/libanki/json/model/ModelTest.java diff --git a/AnkiDroid/src/main/java/com/ichi2/libanki/json/model/Field.java b/AnkiDroid/src/main/java/com/ichi2/libanki/json/model/Field.java new file mode 100755 index 000000000000..608d82fe5cc7 --- /dev/null +++ b/AnkiDroid/src/main/java/com/ichi2/libanki/json/model/Field.java @@ -0,0 +1,146 @@ + +package com.ichi2.libanki.json.model; + +import java.util.ArrayList; +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.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Field { + + @JsonProperty("name") + private String mName; + @JsonProperty("ord") + private long mOrd; + @JsonProperty("sticky") + private boolean mSticky; + @JsonProperty("rtl") + private boolean mRtl; + @JsonProperty("font") + private String mFont; + @JsonProperty("size") + private long mSize; + @JsonProperty("media") + private List mMedia = new ArrayList(); + @JsonProperty("single line") + private boolean mSingleLine; + @JsonIgnore + private final Map 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 media, boolean singleLine) { + super(); + this.mName = name; + this.mOrd = ord; + this.mSticky = sticky; + this.mRtl = rtl; + this.mFont = font; + this.mSize = size; + this.mMedia = media; + this.mSingleLine = singleLine; + } + + @JsonProperty("name") + public String getName() { + return mName; + } + + @JsonProperty("name") + public void setName(String name) { + this.mName = name; + } + + @JsonProperty("ord") + public long getOrd() { + return mOrd; + } + + @JsonProperty("ord") + public void setOrd(long ord) { + this.mOrd = ord; + } + + @JsonProperty("sticky") + public boolean isSticky() { + return mSticky; + } + + @JsonProperty("sticky") + public void setSticky(boolean sticky) { + this.mSticky = sticky; + } + + @JsonProperty("rtl") + public boolean isRtl() { + return mRtl; + } + + @JsonProperty("rtl") + public void setRtl(boolean rtl) { + this.mRtl = rtl; + } + + @JsonProperty("font") + public String getFont() { + return mFont; + } + + @JsonProperty("font") + public void setFont(String font) { + this.mFont = font; + } + + @JsonProperty("size") + public long getSize() { + return mSize; + } + + @JsonProperty("size") + public void setSize(long size) { + this.mSize = size; + } + + @JsonProperty("media") + public List getMedia() { + return mMedia; + } + + @JsonProperty("media") + public void setMedia(List media) { + this.mMedia = media; + } + + @JsonProperty("single line") + public boolean isSingleLine() { + return mSingleLine; + } + + @JsonProperty("single line") + public void setSingleLine(boolean singleLine) { + this.mSingleLine = singleLine; + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.mAdditionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.mAdditionalProperties.put(name, value); + } + +} diff --git a/AnkiDroid/src/main/java/com/ichi2/libanki/json/model/Model.java b/AnkiDroid/src/main/java/com/ichi2/libanki/json/model/Model.java new file mode 100755 index 000000000000..1b7d2c4294c4 --- /dev/null +++ b/AnkiDroid/src/main/java/com/ichi2/libanki/json/model/Model.java @@ -0,0 +1,269 @@ + +package com.ichi2.libanki.json.model; + +import android.annotation.SuppressLint; + +import java.util.ArrayList; +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.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +@SuppressLint("NonPublicNonStaticFieldName") +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Model { + + @JsonProperty("id") + private long id; + + @JsonProperty("name") + private String name; + + @JsonProperty("type") + private long type; + + @JsonProperty("mod") + private long mod; + + @JsonProperty("usn") + private long usn; + + @JsonProperty("sortf") + private long mSortingField; + + @JsonProperty("did") + private long mDeckId; + + @JsonProperty("tmpls") + private List