You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2022/12/22 12:16:46 UTC
[dubbo] branch 3.1 updated: 1.test JSONObject to personMap pojo, the personMap extends HashMap (#11177)
This is an automated email from the ASF dual-hosted git repository.
albumenj pushed a commit to branch 3.1
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.1 by this push:
new 513bdf56b0 1.test JSONObject to personMap pojo, the personMap extends HashMap (#11177)
513bdf56b0 is described below
commit 513bdf56b0344bf905371c7423b6d1206c74373a
Author: xieshouyu <23...@qq.com>
AuthorDate: Thu Dec 22 20:16:40 2022 +0800
1.test JSONObject to personMap pojo, the personMap extends HashMap (#11177)
* 1.test JSONObject to personMap pojo, the personMap extends HashMap
* 1.add LICENSE-2.0
* 1.update LICENSE-2.0 to first row
Co-authored-by: 水手 <xi...@cai-inc.com>
---
.../dubbo/common/model/person/PersonMap.java | 45 ++++++++++++++++++++++
.../apache/dubbo/common/utils/PojoUtilsTest.java | 12 +++++-
2 files changed, 56 insertions(+), 1 deletion(-)
diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/model/person/PersonMap.java b/dubbo-common/src/test/java/org/apache/dubbo/common/model/person/PersonMap.java
new file mode 100644
index 0000000000..2217d6a46e
--- /dev/null
+++ b/dubbo-common/src/test/java/org/apache/dubbo/common/model/person/PersonMap.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.common.model.person;
+
+import java.util.HashMap;
+
+public class PersonMap extends HashMap<String, String> {
+
+ private static final String ID = "1";
+ private static final String NAME = "hand";
+
+ String personId;
+ String personName;
+
+ public String getPersonId() {
+ return get(ID);
+ }
+
+ public void setPersonId(String personId) {
+ this.personId = personId;
+ }
+
+ public String getPersonName() {
+ return get(NAME);
+ }
+
+ public void setPersonName(String personName) {
+ this.personName = personName;
+ }
+}
+
diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/PojoUtilsTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/PojoUtilsTest.java
index 2c7a0b8032..49caf104a5 100644
--- a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/PojoUtilsTest.java
+++ b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/PojoUtilsTest.java
@@ -22,6 +22,7 @@ import org.apache.dubbo.common.model.User;
import org.apache.dubbo.common.model.person.BigPerson;
import org.apache.dubbo.common.model.person.FullAddress;
import org.apache.dubbo.common.model.person.PersonInfo;
+import org.apache.dubbo.common.model.person.PersonMap;
import org.apache.dubbo.common.model.person.PersonStatus;
import org.apache.dubbo.common.model.person.Phone;
@@ -765,7 +766,7 @@ class PojoUtilsTest {
@Test
void testJava8Time() {
-
+
Object localDateTimeGen = PojoUtils.generalize(LocalDateTime.now());
Object localDateTime = PojoUtils.realize(localDateTimeGen, LocalDateTime.class);
assertEquals(localDateTimeGen, localDateTime.toString());
@@ -779,6 +780,15 @@ class PojoUtilsTest {
assertEquals(localTimeGen, localTime.toString());
}
+ @Test
+ public void testJSONObjectToPersonMapPojo() {
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("personId", "1");
+ jsonObject.put("personName", "hand");
+ Object result = PojoUtils.realize(jsonObject, PersonMap.class);
+ assertEquals(PersonMap.class, result.getClass());
+ }
+
public enum Day {
SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY
}