@Test public void fromJson() { Error e = Error.get("a", "b", "c"); JsonNode node = e.toJson(); Error fromJson = Error.fromJson(node); Assert.assertEquals("a", fromJson.getContext()); Assert.assertEquals("b", fromJson.getErrorCode()); Assert.assertEquals("c", fromJson.getMsg()); }
public static Error fromJson(JsonNode node) { if (node instanceof ObjectNode) { String e = null; String m = null; JsonNode x; x = ((ObjectNode) node).get("errorCode"); if (x != null) { e = x.asText(); } x = ((ObjectNode) node).get("msg"); if (x != null) { m = x.asText(); } Error ret = new Error(e, m); x = ((ObjectNode) node).get("context"); if (x != null) { StringTokenizer tok = new StringTokenizer(x.asText(), "/"); while (tok.hasMoreTokens()) { ret.pushContext(tok.nextToken()); } } return ret; } return null; }
Error extends RuntimeException { public static Error fromJson(JsonNode node) { if (node instanceof ObjectNode) { String e = null; String m = null; JsonNode x; x = ((ObjectNode) node).get("errorCode"); if (x != null) { e = x.asText(); } x = ((ObjectNode) node).get("msg"); if (x != null) { m = x.asText(); } Error ret = new Error(e, m); x = ((ObjectNode) node).get("context"); if (x != null) { StringTokenizer tok = new StringTokenizer(x.asText(), "/"); while (tok.hasMoreTokens()) { ret.pushContext(tok.nextToken()); } } return ret; } return null; } }
Error extends RuntimeException { public static Error fromJson(JsonNode node) { if (node instanceof ObjectNode) { String e = null; String m = null; JsonNode x; x = ((ObjectNode) node).get("errorCode"); if (x != null) { e = x.asText(); } x = ((ObjectNode) node).get("msg"); if (x != null) { m = x.asText(); } Error ret = new Error(e, m); x = ((ObjectNode) node).get("context"); if (x != null) { StringTokenizer tok = new StringTokenizer(x.asText(), "/"); while (tok.hasMoreTokens()) { ret.pushContext(tok.nextToken()); } } return ret; } return null; } private  Error(String errorCode, String msg); private  Error(ArrayDeque<String> context, String errorCode, String msg); }
Error extends RuntimeException { public static Error fromJson(JsonNode node) { if (node instanceof ObjectNode) { String e = null; String m = null; JsonNode x; x = ((ObjectNode) node).get("errorCode"); if (x != null) { e = x.asText(); } x = ((ObjectNode) node).get("msg"); if (x != null) { m = x.asText(); } Error ret = new Error(e, m); x = ((ObjectNode) node).get("context"); if (x != null) { StringTokenizer tok = new StringTokenizer(x.asText(), "/"); while (tok.hasMoreTokens()) { ret.pushContext(tok.nextToken()); } } return ret; } return null; } private  Error(String errorCode, String msg); private  Error(ArrayDeque<String> context, String errorCode, String msg); static void push(String context); static void pop(); static Error get(String ctx, String errorCode, String msg); static Error get(String ctx, String errorCode, Throwable e); static Error get(String errorCode, String msg); static Error get(String errorCode, Throwable e); static Error get(Throwable e); static Error get(String errorCode); static void reset(); void pushContext(String context); void popContext(); String getErrorCode(); String getMsg(); String getContext(); JsonNode toJson(); @Override String toString(); @Override String getMessage(); static Error fromJson(JsonNode node); }
Error extends RuntimeException { public static Error fromJson(JsonNode node) { if (node instanceof ObjectNode) { String e = null; String m = null; JsonNode x; x = ((ObjectNode) node).get("errorCode"); if (x != null) { e = x.asText(); } x = ((ObjectNode) node).get("msg"); if (x != null) { m = x.asText(); } Error ret = new Error(e, m); x = ((ObjectNode) node).get("context"); if (x != null) { StringTokenizer tok = new StringTokenizer(x.asText(), "/"); while (tok.hasMoreTokens()) { ret.pushContext(tok.nextToken()); } } return ret; } return null; } private  Error(String errorCode, String msg); private  Error(ArrayDeque<String> context, String errorCode, String msg); static void push(String context); static void pop(); static Error get(String ctx, String errorCode, String msg); static Error get(String ctx, String errorCode, Throwable e); static Error get(String errorCode, String msg); static Error get(String errorCode, Throwable e); static Error get(Throwable e); static Error get(String errorCode); static void reset(); void pushContext(String context); void popContext(); String getErrorCode(); String getMsg(); String getContext(); JsonNode toJson(); @Override String toString(); @Override String getMessage(); static Error fromJson(JsonNode node); static final char DELIMITER; }