Skip to content

Commit 5c1875f

Browse files
committed
Add Utils.unescapeHtml
1 parent e188be2 commit 5c1875f

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

src/AndroidClient/android/src/main/java/net/servicestack/client/JsonUtils.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,15 @@ public static long asLong(JsonObject obj, String key, long defaultValue) {
5656
: defaultValue;
5757
}
5858

59+
private static Gson gson;
5960
public static Gson getGson(){
60-
return new GsonBuilder().disableHtmlEscaping().create();
61+
return gson != null
62+
? gson
63+
: (gson = new GsonBuilder().disableHtmlEscaping().create());
64+
}
65+
66+
public static void setGson(Gson value){
67+
gson = value;
6168
}
6269

6370
public static <T> T fromJson(String json, Class<?> cls) {

src/AndroidClient/android/src/main/java/net/servicestack/client/Utils.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,4 +903,13 @@ public static String getStackTrace(Exception ex) {
903903
ex.printStackTrace(new PrintWriter(sw));
904904
return sw.toString();
905905
}
906+
907+
public static String unescapeHtml(String html){
908+
return html
909+
.replace("&lt;","<")
910+
.replace("&gt;",">")
911+
.replace("&amp;","&")
912+
.replace("&#39;","\'")
913+
.replace("&quot;","\"");
914+
}
906915
}

src/AndroidClient/client/src/main/java/net/servicestack/client/JsonUtils.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,15 @@ public static long asLong(JsonObject obj, String key, long defaultValue) {
5656
: defaultValue;
5757
}
5858

59+
private static Gson gson;
5960
public static Gson getGson(){
60-
return new GsonBuilder().disableHtmlEscaping().create();
61+
return gson != null
62+
? gson
63+
: (gson = new GsonBuilder().disableHtmlEscaping().create());
64+
}
65+
66+
public static void setGson(Gson value){
67+
gson = value;
6168
}
6269

6370
public static <T> T fromJson(String json, Class<?> cls) {

src/AndroidClient/client/src/main/java/net/servicestack/client/Utils.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,4 +903,13 @@ public static String getStackTrace(Exception ex) {
903903
ex.printStackTrace(new PrintWriter(sw));
904904
return sw.toString();
905905
}
906+
907+
public static String unescapeHtml(String html){
908+
return html
909+
.replace("&lt;","<")
910+
.replace("&gt;",">")
911+
.replace("&amp;","&")
912+
.replace("&#39;","\'")
913+
.replace("&quot;","\"");
914+
}
906915
}

0 commit comments

Comments
 (0)