• R/O
  • SSH
  • HTTPS

jsonic: コミット


コミットメタ情報

リビジョン1860 (tree)
日時2015-07-23 21:11:58
作者hizuno

ログメッセージ

java.nio.Path 対応

変更サマリ

差分

--- trunk/jsonic-1.3/docs/index.html (revision 1859)
+++ trunk/jsonic-1.3/docs/index.html (revision 1860)
@@ -172,7 +172,7 @@
172172 <tr><td>java.sql.Array, java.sql.Struct</td></tr>
173173 <tr><td>char[], CharSequence</td><td rowspan="3">string</td></tr>
174174 <tr><td>char, Character</td></tr>
175-<tr><td>TimeZone, Pattern, File, URL, URI, Type, Member, Charset, UUID, java.timeの各クラス</td></tr>
175+<tr><td>TimeZone, Pattern, File, URL, URI, Path, Type, Member, Charset, UUID, java.timeの各クラス</td></tr>
176176 <tr><td>byte[]</td><td>string (BASE64エンコード)</td></tr>
177177 <tr><td>java.sql.RowId</td><td>string (シリアル化後、BASE64エンコード)</td></tr>
178178 <tr><td>Locale</td><td>string (言語コード-国コードあるいは言語コード-国コード-バリアントコード)</td></tr>
@@ -245,7 +245,7 @@
245245 <tr><td>Class, Charset</td><td>指定された型(文字列をforNameにより変換)</td></tr>
246246 <tr><td>TimeZone</td><td>TimeZone(文字列をTimeZone.getTimeZoneを使い変換)</td></tr>
247247 <tr><td>UUID</td><td>UUID(文字列をUUID.fromStringで変換)</td></tr>
248-<tr><td>File, URI, URL</td><td>指定された型(文字列をコンストラクタの引数に指定し変換)</td></tr>
248+<tr><td>File, URI, URL, Path</td><td>指定された型(文字列をコンストラクタの引数に指定し変換)</td></tr>
249249 <tr><td>InetAddress</td><td>InetAddress(文字列をInetAddress.getByNameで変換)</td></tr>
250250 <tr><td>boolean, Boolean</td><td>指定された型("", "false", "no", "off", "NaN"の時false、その他の時true)</td></tr>
251251 <tr><td rowspan="5">number</td><td>なし, Object, Number, BigDecimal</td><td>BigDecimal</td></tr>
@@ -867,6 +867,11 @@
867867
868868 <h2 id="releasenote">リリースノート</h2>
869869
870+<h3>2015/7/23 version 1.3.9</h3>
871+<ul>
872+<li>[機能追加] Java7 の java.nio.Path 型に対応しました。</li>
873+</ul>
874+
870875 <h3>2015/6/29 version 1.3.8</h3>
871876 <ul>
872877 <li>[仕様変更] コンパイル可能な環境の構築が難しくなってきたため、Java 5 のサポートを廃止しました。Java 6 以降をご利用ください。</li>
--- trunk/jsonic-1.3/pom.xml (revision 1859)
+++ trunk/jsonic-1.3/pom.xml (revision 1860)
@@ -7,7 +7,7 @@
77 <artifactId>jsonic</artifactId>
88 <packaging>jar</packaging>
99 <name>jsonic</name>
10- <version>1.3.8</version>
10+ <version>1.3.9</version>
1111 <description>simple json encoder/decoder for java</description>
1212 <url>http://jsonic.sourceforge.jp/</url>
1313 <licenses>
--- trunk/jsonic-1.3/test/net/arnx/jsonic/JSONJava8Test.java (revision 1859)
+++ trunk/jsonic-1.3/test/net/arnx/jsonic/JSONJava8Test.java (revision 1860)
@@ -3,6 +3,8 @@
33 import static org.junit.Assert.*;
44
55 import java.math.BigDecimal;
6+import java.nio.file.Path;
7+import java.nio.file.Paths;
68 import java.time.Duration;
79 import java.time.Instant;
810 import java.time.LocalDate;
@@ -91,6 +93,12 @@
9193 + "\"optionalInt\":null,"
9294 + "\"optionalLong\":null"
9395 + "}", JSON.encode(obean));
96+
97+ PathBean pbean = new PathBean();
98+ pbean.path = Paths.get("./test.txt");
99+ assertEquals("{"
100+ + "\"path\":\".\\\\test.txt\""
101+ + "}", JSON.encode(pbean));
94102 }
95103
96104 @Test
@@ -157,6 +165,13 @@
157165 + "\"optionalInt\":null,"
158166 + "\"optionalLong\":null"
159167 + "}", Java8OptionalBean.class));
168+
169+ PathBean pbean = new PathBean();
170+ pbean.path = Paths.get("./test.txt");
171+ assertEquals(pbean, JSON.decode("{"
172+ + "\"path\":\".\\\\test.txt\""
173+ + "}", PathBean.class));
174+
160175 }
161176
162177 public static class Java8DataTimeAPIBean {
@@ -413,4 +428,38 @@
413428 return "OptionalBeanBean [text=" + text + "]";
414429 }
415430 }
431+
432+ public static class PathBean {
433+ public Path path;
434+
435+ @Override
436+ public int hashCode() {
437+ final int prime = 31;
438+ int result = 1;
439+ result = prime * result + ((path == null) ? 0 : path.hashCode());
440+ return result;
441+ }
442+
443+ @Override
444+ public boolean equals(Object obj) {
445+ if (this == obj)
446+ return true;
447+ if (obj == null)
448+ return false;
449+ if (getClass() != obj.getClass())
450+ return false;
451+ PathBean other = (PathBean) obj;
452+ if (path == null) {
453+ if (other.path != null)
454+ return false;
455+ } else if (!path.equals(other.path))
456+ return false;
457+ return true;
458+ }
459+
460+ @Override
461+ public String toString() {
462+ return "PathBean [path=" + path + "]";
463+ }
464+ }
416465 }
--- trunk/jsonic-1.3/src/net/arnx/jsonic/Formatter.java (revision 1859)
+++ trunk/jsonic-1.3/src/net/arnx/jsonic/Formatter.java (revision 1860)
@@ -24,6 +24,7 @@
2424 import java.lang.reflect.Type;
2525 import java.net.InetAddress;
2626 import java.nio.charset.Charset;
27+import java.nio.file.Path;
2728 import java.sql.RowId;
2829 import java.sql.SQLException;
2930 import java.sql.Struct;
@@ -49,14 +50,6 @@
4950 import java.util.RandomAccess;
5051 import java.util.TimeZone;
5152
52-import net.arnx.jsonic.JSON.Context;
53-import net.arnx.jsonic.JSON.Mode;
54-import net.arnx.jsonic.io.OutputSource;
55-import net.arnx.jsonic.util.Base64;
56-import net.arnx.jsonic.util.BeanInfo;
57-import net.arnx.jsonic.util.ClassUtil;
58-import net.arnx.jsonic.util.PropertyInfo;
59-
6053 import org.apache.commons.beanutils.DynaBean;
6154 import org.apache.commons.beanutils.DynaProperty;
6255 import org.w3c.dom.Attr;
@@ -70,6 +63,14 @@
7063 import org.w3c.dom.NodeList;
7164 import org.w3c.dom.Text;
7265
66+import net.arnx.jsonic.JSON.Context;
67+import net.arnx.jsonic.JSON.Mode;
68+import net.arnx.jsonic.io.OutputSource;
69+import net.arnx.jsonic.util.Base64;
70+import net.arnx.jsonic.util.BeanInfo;
71+import net.arnx.jsonic.util.ClassUtil;
72+import net.arnx.jsonic.util.PropertyInfo;
73+
7374 interface Formatter {
7475 boolean accept(Object o);
7576 boolean isStruct();
@@ -482,6 +483,27 @@
482483 }
483484 }
484485
486+final class PathFormatter implements Formatter {
487+ public PathFormatter() {
488+ }
489+
490+ @Override
491+ public boolean accept(Object o) {
492+ return o instanceof Path;
493+ }
494+
495+ @Override
496+ public boolean isStruct() {
497+ return false;
498+ }
499+
500+ @Override
501+ public void format(final Context context, final Object src, final Object o, final OutputSource out) throws Exception {
502+ StringFormatter.INSTANCE.format(context, src, o, out);
503+ }
504+}
505+
506+
485507 final class RowIdFormatter implements Formatter {
486508 public RowIdFormatter() {
487509 }
@@ -488,7 +510,7 @@
488510
489511 @Override
490512 public boolean accept(Object o) {
491- return o != null && RowId.class.isAssignableFrom(o.getClass());
513+ return o instanceof RowId;
492514 }
493515
494516 @Override
--- trunk/jsonic-1.3/src/net/arnx/jsonic/Converter.java (revision 1859)
+++ trunk/jsonic-1.3/src/net/arnx/jsonic/Converter.java (revision 1860)
@@ -33,6 +33,8 @@
3333 import java.net.URI;
3434 import java.net.URL;
3535 import java.nio.charset.Charset;
36+import java.nio.file.Path;
37+import java.nio.file.Paths;
3638 import java.sql.Struct;
3739 import java.text.DateFormat;
3840 import java.text.NumberFormat;
@@ -1022,6 +1024,33 @@
10221024 }
10231025 }
10241026
1027+final class PathConverter implements Converter {
1028+ public PathConverter() {
1029+ }
1030+
1031+ @Override
1032+ public boolean accept(Class<?> cls) {
1033+ return Path.class.isAssignableFrom(cls);
1034+ }
1035+
1036+ public Object convert(Context context, Object value, Class<?> c, Type t) throws Exception {
1037+ if (value == null) {
1038+ return null;
1039+ } else if (value instanceof Map<?, ?>) {
1040+ value = ((Map<?,?>)value).get(null);
1041+ } else if (value instanceof List<?>) {
1042+ List<?> src = (List<?>)value;
1043+ value = (!src.isEmpty()) ? src.get(0) : null;
1044+ }
1045+
1046+ if (value == null) {
1047+ return null;
1048+ } else {
1049+ return Paths.get(value.toString());
1050+ }
1051+ }
1052+}
1053+
10251054 final class EnumConverter implements Converter {
10261055 public static final EnumConverter INSTANCE = new EnumConverter();
10271056
--- trunk/jsonic-1.3/src/net/arnx/jsonic/JSON.java (revision 1859)
+++ trunk/jsonic-1.3/src/net/arnx/jsonic/JSON.java (revision 1860)
@@ -267,6 +267,9 @@
267267 FORMAT_MAP.put(TreeMap.class, MapFormatter.INSTANCE);
268268 FORMAT_MAP.put(LinkedHashMap.class, MapFormatter.INSTANCE);
269269
270+ formatter = getFormatterInstance(PACKAGE_NAME + ".PathFormatter", cl);
271+ if (formatter != null) FORMAT_LIST.add(formatter);
272+
270273 FORMAT_LIST.add(EnumFormatter.INSTANCE);
271274 FORMAT_LIST.add(MapFormatter.INSTANCE);
272275 FORMAT_LIST.add(ListFormatter.INSTANCE);
@@ -390,6 +393,9 @@
390393 converter = getConverterInstance(PACKAGE_NAME + ".MonthConverter", cl);
391394 if (converter != null) CONVERT_LIST.add(converter);
392395
396+ converter = getConverterInstance(PACKAGE_NAME + ".PathConverter", cl);
397+ if (converter != null) CONVERT_LIST.add(converter);
398+
393399 CONVERT_LIST.add(EnumConverter.INSTANCE);
394400 CONVERT_LIST.add(PropertiesConverter.INSTANCE);
395401 CONVERT_LIST.add(MapConverter.INSTANCE);
旧リポジトリブラウザで表示