Skip to content

question/issue about reading Object as JsonObject #1156

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

Closed
mikereiche opened this issue Jul 12, 2021 · 3 comments
Closed

question/issue about reading Object as JsonObject #1156

mikereiche opened this issue Jul 12, 2021 · 3 comments
Assignees
Labels
in: repository Repositories abstraction type: enhancement A general enhancement

Comments

@mikereiche
Copy link
Collaborator

mikereiche commented Jul 12, 2021

question/issue about reading object as JsonObject (instead of empty java.lang.Obect)
From Davide Pellegatta

It’s about object mapping in spring-data-couchbase for very generic objects:
@DaTa
@with
@AllArgsConstructor
@NoArgsConstructor
@document
public class Note {
@id
private String id;
private Map<String, Object> json;
}

basically my customer would like to work with something like this. I don’t think it’s possible to make it work. But I’d like to double check this
I already point them to CouchbaseTemplate for this, but at the same time I’d want to be sure as this with the mongo implementation works just fine.

@mikereiche
Copy link
Collaborator Author

mikereiche commented Jul 12, 2021

Couchbase does not currently read it as a Map - it would need to assume that an Object is a map like this: (about line 353 in MappingCouchbaseConverter)

 	protected Map<Object, Object> readMap(final TypeInformation<?> type, final CouchbaseDocument source,
			final Object parent) 
.
.
.

			TypeInformation<?> valueType = type.getMapValueType();
			if (value instanceof CouchbaseDocument) {
				if (valueType.getType().equals(Object.class)) {
					map.put(key, readMap(type, (CouchbaseDocument) value, source));
				} else {
					map.put(key, read(valueType, (CouchbaseDocument) value, parent));
				}

@mikereiche mikereiche self-assigned this Jul 15, 2021
@davidepellegatta
Copy link

Thank you Mike! do you think this is something worth adding or better go for a custom converter?

@mikereiche mikereiche added in: repository Repositories abstraction type: enhancement A general enhancement labels Jul 26, 2021
@mikereiche
Copy link
Collaborator Author

#1650 Added converters for JsonNode, JsonObject and JsonArray

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: repository Repositories abstraction type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants