You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juneau.apache.org by ja...@apache.org on 2019/07/25 18:16:35 UTC
[juneau] branch master updated: JUNEAU-127 Clean up usage of
PojoSwaps in ClassMeta
This is an automated email from the ASF dual-hosted git repository.
jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git
The following commit(s) were added to refs/heads/master by this push:
new 80f53f0 JUNEAU-127 Clean up usage of PojoSwaps in ClassMeta
80f53f0 is described below
commit 80f53f0553ec6826e31035827bad5ed5aca7232a
Author: JamesBognar <ja...@apache.org>
AuthorDate: Thu Jul 25 14:16:21 2019 -0400
JUNEAU-127 Clean up usage of PojoSwaps in ClassMeta
---
.../src/main/java/org/apache/juneau/ClassMeta.java | 47 ++--------------------
.../apache/juneau/transform/DefaultTransforms.java | 13 +++---
2 files changed, 12 insertions(+), 48 deletions(-)
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java
index 7bc11a8..ff9e58d 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/ClassMeta.java
@@ -35,7 +35,6 @@ import org.apache.juneau.parser.*;
import org.apache.juneau.reflect.*;
import org.apache.juneau.serializer.*;
import org.apache.juneau.transform.*;
-import org.apache.juneau.transforms.*;
import org.apache.juneau.utils.*;
/**
@@ -475,14 +474,6 @@ public final class ClassMeta<T> implements Type {
}
// TODO - should use transforms for above code.
- // Special cases
- try {
- if (c == TimeZone.class)
- fromStringMethod = c.getMethod("getTimeZone", String.class);
- else if (c == Locale.class)
- fromStringMethod = LocaleAsString.class.getMethod("fromString", String.class);
- } catch (NoSuchMethodException e1) {}
-
// Find swap() method if present.
for (MethodInfo m : ci.getPublicMethods()) {
if (m.isAll(PUBLIC, NOT_DEPRECATED, NOT_STATIC) && (m.hasName("swap") || m.hasName("toMap")) && m.hasFuzzyArgs(BeanSession.class)) {
@@ -625,10 +616,10 @@ public final class ClassMeta<T> implements Type {
);
}
- if (Enumeration.class.isAssignableFrom(c))
- this.pojoSwaps.add(new EnumerationSwap());
- else if (Iterator.class.isAssignableFrom(c))
- this.pojoSwaps.add(new IteratorSwap());
+ PojoSwap defaultSwap = DefaultTransforms.findDefaultSwap(c);
+ if (defaultSwap != null)
+ this.pojoSwaps.add(defaultSwap);
+
if (pojoSwaps != null)
this.pojoSwaps.addAll(Arrays.asList(pojoSwaps));
@@ -1982,36 +1973,6 @@ public final class ClassMeta<T> implements Type {
return innerClass.getSimpleName();
}
- private static class LocaleAsString {
- private static Method forLanguageTagMethod;
- static {
- try {
- forLanguageTagMethod = Locale.class.getMethod("forLanguageTag", String.class);
- } catch (NoSuchMethodException e) {}
- }
-
- @SuppressWarnings("unused")
- public static final Locale fromString(String localeString) {
- if (forLanguageTagMethod != null) {
- if (localeString.indexOf('_') != -1)
- localeString = localeString.replace('_', '-');
- try {
- return (Locale)forLanguageTagMethod.invoke(null, localeString);
- } catch (Exception e) {
- throw new BeanRuntimeException(e);
- }
- }
- String[] v = localeString.toString().split("[\\-\\_]");
- if (v.length == 1)
- return new Locale(v[0]);
- else if (v.length == 2)
- return new Locale(v[0], v[1]);
- else if (v.length == 3)
- return new Locale(v[0], v[1], v[2]);
- throw new BeanRuntimeException("Could not convert string ''{0}'' to a Locale.", localeString);
- }
- }
-
@Override /* Object */
public int hashCode() {
return super.hashCode();
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/transform/DefaultTransforms.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/transform/DefaultTransforms.java
index 309ae44..445e12e 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/transform/DefaultTransforms.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/transform/DefaultTransforms.java
@@ -15,7 +15,10 @@ package org.apache.juneau.transform;
import java.util.*;
import java.util.concurrent.*;
+import javax.xml.datatype.*;
+
import org.apache.juneau.reflect.*;
+import org.apache.juneau.transforms.*;
/**
* Maintain the list of default PojoSwaps used by all serializers and parsers.
@@ -25,16 +28,16 @@ public class DefaultTransforms {
private static final Map<Class<?>,PojoSwap<?,?>> POJO_SWAPS = new ConcurrentHashMap<>();
static {
// POJO_SWAPS.put(byte[].class, new ByteArrayBase64Swap());
-// POJO_SWAPS.put(Enumeration.class, new EnumerationSwap());
+ POJO_SWAPS.put(Enumeration.class, new EnumerationSwap());
// POJO_SWAPS.put(InputStream.class, new InputStreamBase64Swap());
-// POJO_SWAPS.put(Iterator.class, new IteratorSwap());
-// POJO_SWAPS.put(Locale.class, new LocaleSwap());
+ POJO_SWAPS.put(Iterator.class, new IteratorSwap());
+ POJO_SWAPS.put(Locale.class, new LocaleSwap());
// POJO_SWAPS.put(Reader.class, new ReaderSwap());
// POJO_SWAPS.put(Calendar.class, new TemporalCalendarSwap.IsoInstant());
// POJO_SWAPS.put(Date.class, new TemporalCalendarSwap.IsoInstant());
// POJO_SWAPS.put(Temporal.class, new TemporalCalendarSwap.IsoInstant());
-// POJO_SWAPS.put(TimeZone.class, new TimeZoneSwap());
-// POJO_SWAPS.put(XMLGregorianCalendar.class, new XMLGregorianCalendarSwap());
+ POJO_SWAPS.put(TimeZone.class, new TimeZoneSwap());
+ POJO_SWAPS.put(XMLGregorianCalendar.class, new XMLGregorianCalendarSwap());
}
/**