jinmeiliao commented on a change in pull request #6629:
URL: https://github.com/apache/geode/pull/6629#discussion_r661651460
##########
File path:
geode-core/src/main/java/org/apache/geode/pdx/internal/json/PdxToJSON.java
##########
@@ -224,9 +226,15 @@ private void getJSONStringFromArray(JsonGenerator jg,
Object value, String pf)
writeValue(jg, obj, pf);
}
jg.writeEndArray();
+ } else if (value.getClass().isArray()) {
+ throw new IllegalStateException(
+ "The pdx field " + pf + " is an array whose component type "
+ + value.getClass().getComponentType()
+ + " can not be converted to JSON.");
} else {
throw new IllegalStateException(
- "PdxInstance returns unknown pdxfield " + pf + " for type " + value);
+ "Expected an array for pdx field " + pf + ", but got an object of
type "
Review comment:
since only array object will call this method, this "else" statement
will never be executed. I think this if/else is redundant.
##########
File path:
geode-web-api/src/test/java/org/apache/geode/rest/internal/web/util/JsonWriterTest.java
##########
@@ -0,0 +1,54 @@
+/*
+ * 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.geode.rest.internal.web.util;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Fail.fail;
+import static org.mockito.Mockito.mock;
+
+import java.io.IOException;
+import java.util.Date;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.test.junit.categories.RestAPITest;
+
+@Category({RestAPITest.class})
+public class JsonWriterTest {
+ @Test
+ public void testWwriteArrayAsJson() throws IOException {
+ Date value = new Date();
+ try {
Review comment:
it's probably cleaner to use 'assertThatThrownBy` method
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]