Line 1... |
Line 1... |
1 |
/*
|
1 |
/*
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
3 |
*
|
3 |
*
|
4 |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
|
4 |
* Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
|
5 |
*
|
5 |
*
|
6 |
* The contents of this file are subject to the terms of the GNU General Public License Version 3
|
6 |
* The contents of this file are subject to the terms of the GNU General Public License Version 3
|
7 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
|
7 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
|
8 |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
|
8 |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
|
9 |
* language governing permissions and limitations under the License.
|
9 |
* language governing permissions and limitations under the License.
|
Line 71... |
Line 71... |
71 |
} else if (param instanceof Date) {
|
71 |
} else if (param instanceof Date) {
|
72 |
result = format((Date) param);
|
72 |
result = format((Date) param);
|
73 |
} else if (param instanceof Calendar) {
|
73 |
} else if (param instanceof Calendar) {
|
74 |
result = formatCalendar(((Calendar) param));
|
74 |
result = formatCalendar(((Calendar) param));
|
75 |
} else if (param instanceof Class<?>) {
|
75 |
} else if (param instanceof Class<?>) {
|
- |
|
76 |
if (param == String.class) {
|
- |
|
77 |
result = "string";
|
- |
|
78 |
} else {
|
76 |
result = ((Class<?>) param).getName();
|
79 |
result = ((Class<?>) param).getName();
|
- |
|
80 |
}
|
77 |
} else if (param instanceof Iterable) {
|
81 |
} else if (param instanceof Iterable) {
|
78 |
final Iterable<?> tmp = (Iterable<?>) param;
|
82 |
final Iterable<?> tmp = (Iterable<?>) param;
|
79 |
final JSONArray jsonArray = new JSONArray();
|
83 |
final JSONArray jsonArray = new JSONArray();
|
80 |
for (Object o : tmp) {
|
84 |
for (Object o : tmp) {
|
81 |
jsonArray.add(getJSON(o));
|
85 |
jsonArray.add(getJSON(o));
|
82 |
}
|
86 |
}
|
83 |
result = jsonArray;
|
87 |
result = jsonArray;
|
84 |
} else if (param instanceof Color) {
|
88 |
} else if (param instanceof Color) {
|
85 |
if (param != null) {
|
- |
|
86 |
final Color paramColor = (Color) param;
|
- |
|
87 |
final JSONObject jsonColor = new JSONObject();
|
- |
|
88 |
jsonColor.put("r", paramColor.getRed());
|
89 |
String hexString = Integer.toHexString(((Color) param).getRGB());
|
89 |
jsonColor.put("g", paramColor.getGreen());
|
90 |
if (hexString.length() > 6) {
|
90 |
jsonColor.put("b", paramColor.getBlue());
|
91 |
hexString = hexString.substring(2, hexString.length());
|
91 |
result = jsonColor;
|
- |
|
92 |
}
|
92 |
}
|
- |
|
93 |
result = "#" + hexString;
|
93 |
} else if (param instanceof BigDecimal) {
|
94 |
} else if (param instanceof BigDecimal) {
|
94 |
result = ((BigDecimal) param).doubleValue();
|
95 |
result = ((BigDecimal) param).doubleValue();
|
95 |
} else {
|
96 |
} else {
|
96 |
result = param;
|
97 |
result = param;
|
97 |
}
|
98 |
}
|
Line 130... |
Line 131... |
130 |
result = type.cast(c);
|
131 |
result = type.cast(c);
|
131 |
} catch (java.text.ParseException e) {
|
132 |
} catch (java.text.ParseException e) {
|
132 |
throw new IllegalArgumentException("object (" + o.getClass().getName() + ") is not assignable for '" + type + "', the format is not valid", e);
|
133 |
throw new IllegalArgumentException("object (" + o.getClass().getName() + ") is not assignable for '" + type + "', the format is not valid", e);
|
133 |
}
|
134 |
}
|
134 |
} else if (type.equals(Color.class)) {
|
135 |
} else if (type.equals(Color.class)) {
|
135 |
final JSONObject jsonColor = (JSONObject) o;
|
- |
|
136 |
final int r = JSONConverter.getParameterFromJSON(jsonColor, "r", Integer.class);
|
- |
|
137 |
final int g = JSONConverter.getParameterFromJSON(jsonColor, "g", Integer.class);
|
- |
|
138 |
final int b = JSONConverter.getParameterFromJSON(jsonColor, "b", Integer.class);
|
- |
|
139 |
result = type.cast(new Color(r, g, b));
|
136 |
result = type.cast(Color.decode(o.toString()));
|
140 |
} else {
|
137 |
} else {
|
141 |
result = type.cast(o);
|
138 |
result = type.cast(o);
|
142 |
}
|
139 |
}
|
143 |
} else {
|
140 |
} else {
|
144 |
result = null;
|
141 |
result = null;
|