Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Iterable types that are not List, Set, or array types #57

Open
mikejhill opened this issue Apr 13, 2018 · 0 comments
Open

Support Iterable types that are not List, Set, or array types #57

mikejhill opened this issue Apr 13, 2018 · 0 comments

Comments

@mikejhill
Copy link
Contributor

Iterable types that do not implement the List or Set interfaces or are array types are serialized as objects rather than collections. It would be helpful to serialize these as arrays.

This causes issues when attempting to serialize other collection types that do not implement the List or Set interfaces, such as java.util.HashMap#values.

The default Jackson implementation appears to serialize Iterable types as collections by default through IterableSerializer (at least I believe it's by default -- it might be a configuration that I'm not seeing).

In order to enable serializing Iterable types as collections, we would need to make a small modification in the JsonViewSerializer#writeList(Object) method:

-    boolean writeList(Object obj) throws IOException {
-      if(obj instanceof List || obj instanceof Set || obj.getClass().isArray()) {
-      // ...
+    boolean writeList(Object obj) throws IOException {
+      if(obj instanceof Iterable || obj.getClass().isArray()) {
+      // ...

Is there any reason not to do this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant