Skip to content

Commit 23a5dac

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 2de749b + 9a259aa commit 23a5dac

File tree

4 files changed

+75
-0
lines changed

4 files changed

+75
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: bug
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the Bug**
11+
A clear and concise description of what the bug is.
12+
13+
**To Reproduce**
14+
Steps to reproduce the behavior:
15+
1. Go to '...'
16+
2. Click on '....'
17+
3. Scroll down to '....'
18+
4. See error
19+
20+
**Expected behavior**
21+
A clear and concise description of what you expected to happen.
22+
23+
**Screenshots / Logs**
24+
If applicable, add screenshots and/or logs to help explain your problem. You can use pastefy.ga to upload large text snippets.
25+
26+
**Environment Information:**
27+
- Java Language Level [e.g. 8]
28+
- Version [e.g. 1.0]
29+
30+
**Additional Context**
31+
Add any other context about the problem here.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: enhancement
6+
assignees: ''
7+
8+
---
9+
10+
**Is your feature request related to a problem? Please describe.**
11+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12+
13+
**Describe the solution you'd like**
14+
A clear and concise description of what you want to happen.
15+
16+
**Describe alternatives you've considered**
17+
A clear and concise description of any alternative solutions or features you've considered.
18+
19+
**Additional context**
20+
Add any other context or screenshots about the feature request here.

src/main/java/org/javawebstack/abstractdata/AbstractMapper.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.google.gson.*;
44
import com.google.gson.annotations.Expose;
5+
import org.javawebstack.abstractdata.util.GsonAbstractDataAdapter;
56

67
public class AbstractMapper {
78

@@ -44,6 +45,11 @@ private Gson gson(){
4445
if(gson != null)
4546
return gson;
4647
GsonBuilder builder = new GsonBuilder()
48+
.registerTypeAdapter(AbstractElement.class, new GsonAbstractDataAdapter<>())
49+
.registerTypeAdapter(AbstractObject.class, new GsonAbstractDataAdapter<>())
50+
.registerTypeAdapter(AbstractArray.class, new GsonAbstractDataAdapter<>())
51+
.registerTypeAdapter(AbstractPrimitive.class, new GsonAbstractDataAdapter<>())
52+
.registerTypeAdapter(AbstractNull.class, new GsonAbstractDataAdapter<>())
4753
.setFieldNamingPolicy(namingPolicy.getGsonPolicy());
4854
if(dateFormat != null)
4955
builder.setDateFormat(dateFormat);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.javawebstack.abstractdata.util;
2+
3+
import com.google.gson.*;
4+
import org.javawebstack.abstractdata.AbstractElement;
5+
6+
import java.lang.reflect.Type;
7+
8+
public class GsonAbstractDataAdapter<T extends AbstractElement> implements JsonSerializer<T>, JsonDeserializer<T> {
9+
10+
public T deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
11+
return (T) AbstractElement.fromJson(jsonElement);
12+
}
13+
14+
public JsonElement serialize(T t, Type type, JsonSerializationContext jsonSerializationContext) {
15+
return t.toJson();
16+
}
17+
18+
}

0 commit comments

Comments
 (0)