From e95b76c44ae7d963694130b2013fb1f58f0c641b Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Thu, 5 Nov 2015 20:43:56 +0000 Subject: [PATCH] Replace tabs with spaces --- .gitattributes | 10 +-- JacksonReplacement/JsonProperty.java | 3 +- JacksonReplacement/JsonRootName.java | 2 +- JacksonReplacement/ObjectMapper.java | 105 +++++++++++++-------------- 4 files changed, 59 insertions(+), 61 deletions(-) diff --git a/.gitattributes b/.gitattributes index 412eeda78..07c52e7ae 100644 --- a/.gitattributes +++ b/.gitattributes @@ -10,13 +10,13 @@ *.dbproj merge=union # Standard to msysgit -*.doc diff=astextplain -*.DOC diff=astextplain +*.doc diff=astextplain +*.DOC diff=astextplain *.docx diff=astextplain *.DOCX diff=astextplain *.dot diff=astextplain *.DOT diff=astextplain *.pdf diff=astextplain -*.PDF diff=astextplain -*.rtf diff=astextplain -*.RTF diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/JacksonReplacement/JsonProperty.java b/JacksonReplacement/JsonProperty.java index 0b4980476..b52b7eeec 100644 --- a/JacksonReplacement/JsonProperty.java +++ b/JacksonReplacement/JsonProperty.java @@ -8,5 +8,6 @@ import java.lang.annotation.Target; @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) @Retention(RetentionPolicy.RUNTIME) public @interface JsonProperty { - String value() default ""; + + String value() default ""; } diff --git a/JacksonReplacement/JsonRootName.java b/JacksonReplacement/JsonRootName.java index 74522d25e..238c73333 100644 --- a/JacksonReplacement/JsonRootName.java +++ b/JacksonReplacement/JsonRootName.java @@ -8,5 +8,5 @@ import java.lang.annotation.Target; @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) public @interface JsonRootName { - String value() default ""; + String value() default ""; } diff --git a/JacksonReplacement/ObjectMapper.java b/JacksonReplacement/ObjectMapper.java index d904517a7..4955c28ea 100644 --- a/JacksonReplacement/ObjectMapper.java +++ b/JacksonReplacement/ObjectMapper.java @@ -11,59 +11,56 @@ import org.json.JSONObject; public class ObjectMapper { - /** - * This takes a JSON string and creates (and populates) an object of the given class - * with the data from that JSON string. It mimics the method signature of the jackson - * JSON API, so that we don't have to import the jackson library into this application. - * - * @param jsonString The JSON string to parse. - * @param objClass The class of object we want to create. - * @return The instantiation of that class, populated with data from the JSON object. - * @throws IOException If there was any kind of issue. - */ - public T readValue(String jsonString, Class objClass) throws IOException { - try { - return readValue(new JSONObject(jsonString), objClass); - } - catch (IOException ioe) { - throw ioe; - } - catch (Exception e) { - e.printStackTrace(); - throw new IOException(e); - } - } + /** + * This takes a JSON string and creates (and populates) an object of the + * given class with the data from that JSON string. It mimics the method + * signature of the jackson JSON API, so that we don't have to import the + * jackson library into this application. + * + * @param jsonString The JSON string to parse. + * @param objClass The class of object we want to create. + * @return The instantiation of that class, populated with data from the + * JSON object. + * @throws IOException If there was any kind of issue. + */ + public T readValue(String jsonString, Class objClass) throws IOException { + try { + return readValue(new JSONObject(jsonString), objClass); + } catch (IOException ioe) { + throw ioe; + } catch (Exception e) { + e.printStackTrace(); + throw new IOException(e); + } + } - @SuppressWarnings("unchecked") - public T readValue(JSONObject json, Class objClass) throws IOException { - try { - //TODO Iterate through json object values and call the JsonAnySetter method on the unknown ones. - T obj = objClass.newInstance(); - for (Field f : objClass.getFields()) { - Annotation a = f.getAnnotation(JsonProperty.class); - if (List.class.equals(f.getType()) && (json.optJSONArray(((JsonProperty) a).value()) != null)) { // It's a list. - JSONArray jsonArray = json.optJSONArray(((JsonProperty) a).value()); - ParameterizedType listType = (ParameterizedType) f.getGenericType(); - Class subObj = (Class) listType.getActualTypeArguments()[0]; - List subObjList = ((Class>) f.getType()).newInstance(); - for (int i = 0; i < jsonArray.length(); i++) { - subObjList.add((R) readValue(jsonArray.getJSONObject(i), subObj)); - } - f.set(obj, subObjList); - } - else if (a != null) { - f.set(obj, json.opt(((JsonProperty) a).value())); - } - } - return obj; - } - catch (IOException ioe) { - throw ioe; - } - catch (Exception e) { - e.printStackTrace(); - throw new IOException(e); - } - } + @SuppressWarnings("unchecked") + public T readValue(JSONObject json, Class objClass) throws IOException { + try { + //TODO Iterate through json object values and call the JsonAnySetter method on the unknown ones. + T obj = objClass.newInstance(); + for (Field f : objClass.getFields()) { + Annotation a = f.getAnnotation(JsonProperty.class); + if (List.class.equals(f.getType()) && (json.optJSONArray(((JsonProperty) a).value()) != null)) { // It's a list. + JSONArray jsonArray = json.optJSONArray(((JsonProperty) a).value()); + ParameterizedType listType = (ParameterizedType) f.getGenericType(); + Class subObj = (Class) listType.getActualTypeArguments()[0]; + List subObjList = ((Class>) f.getType()).newInstance(); + for (int i = 0; i < jsonArray.length(); i++) { + subObjList.add((R) readValue(jsonArray.getJSONObject(i), subObj)); + } + f.set(obj, subObjList); + } else if (a != null) { + f.set(obj, json.opt(((JsonProperty) a).value())); + } + } + return obj; + } catch (IOException ioe) { + throw ioe; + } catch (Exception e) { + e.printStackTrace(); + throw new IOException(e); + } + } -} \ No newline at end of file +}