From d9ad1222139809b212fbcee243dfcba67e001ea5 Mon Sep 17 00:00:00 2001 From: nzomkxia Date: Wed, 9 May 2018 15:28:56 +0800 Subject: [PATCH 1/2] add Locale serialize & deserialize support --- .../common/json/GenericJSONConverter.java | 21 +++++++++++++++++++ .../alibaba/dubbo/common/json/JSONTest.java | 9 ++++++++ 2 files changed, 30 insertions(+) diff --git a/dubbo-common/src/main/java/com/alibaba/dubbo/common/json/GenericJSONConverter.java b/dubbo-common/src/main/java/com/alibaba/dubbo/common/json/GenericJSONConverter.java index 8a67d711ecf..02553aa5356 100644 --- a/dubbo-common/src/main/java/com/alibaba/dubbo/common/json/GenericJSONConverter.java +++ b/dubbo-common/src/main/java/com/alibaba/dubbo/common/json/GenericJSONConverter.java @@ -28,6 +28,7 @@ import java.util.Collection; import java.util.Date; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; @@ -358,6 +359,24 @@ public Object decode(Object jv) throws IOException { } }; GlobalDecoderMap.put(Date.class, d); + + d = new Decoder() { + @Override + public Object decode(Object jv) throws IOException { + if (jv instanceof String) { + String[] items = ((String)jv).split("_"); + if(items.length == 1){ + return new Locale(items[0]); + } + if(items.length == 2){ + return new Locale(items[0], items[1]); + } + return new Locale(items[0], items[1], items[2]); + } + return (Locale)null; + } + }; + GlobalDecoderMap.put(Locale.class, d); } @Override @@ -407,6 +426,8 @@ public void writeValue(Object obj, JSONWriter jb, boolean writeClass) throws IOE writeValue(item, jb, writeClass); } jb.arrayEnd(); + } else if(obj instanceof Locale) { + jb.valueString(obj.toString()); } else { jb.objectBegin(); diff --git a/dubbo-common/src/test/java/com/alibaba/dubbo/common/json/JSONTest.java b/dubbo-common/src/test/java/com/alibaba/dubbo/common/json/JSONTest.java index bc45e87f246..cf631eebb6b 100644 --- a/dubbo-common/src/test/java/com/alibaba/dubbo/common/json/JSONTest.java +++ b/dubbo-common/src/test/java/com/alibaba/dubbo/common/json/JSONTest.java @@ -24,6 +24,7 @@ import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import static org.junit.Assert.assertEquals; @@ -169,6 +170,14 @@ public void testParse2Arguments() throws Exception { assertEquals(test[0], 1); } + @Test + public void testLocale() throws Exception { + Locale obj = Locale.US; + String str = JSON.json(obj); + assertEquals("\"en_US\"", str); + assertEquals(obj, JSON.parse(str, Locale.class)); + } + public static class Bean1 { public int[] array; private String name, displayName; From b19cfd4deb29ae9c2bc79773628b96156aa1e418 Mon Sep 17 00:00:00 2001 From: nzomkxia Date: Thu, 24 May 2018 10:30:28 +0800 Subject: [PATCH 2/2] remove validation key in provider's url #1386 --- .../alibaba/dubbo/registry/integration/RegistryProtocol.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/integration/RegistryProtocol.java b/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/integration/RegistryProtocol.java index 3f5b731745f..fd414edd135 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/integration/RegistryProtocol.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/integration/RegistryProtocol.java @@ -50,6 +50,7 @@ import static com.alibaba.dubbo.common.Constants.ACCEPT_FOREIGN_IP; import static com.alibaba.dubbo.common.Constants.QOS_ENABLE; import static com.alibaba.dubbo.common.Constants.QOS_PORT; +import static com.alibaba.dubbo.common.Constants.VALIDATION_KEY; /** * RegistryProtocol @@ -227,7 +228,8 @@ private URL getRegistedProviderUrl(final Invoker originInvoker) { .removeParameter(Constants.BIND_PORT_KEY) .removeParameter(QOS_ENABLE) .removeParameter(QOS_PORT) - .removeParameter(ACCEPT_FOREIGN_IP); + .removeParameter(ACCEPT_FOREIGN_IP) + .removeParameter(VALIDATION_KEY); return registedProviderUrl; }