Invalid class type on nested object - MappingCouchbaseConverter - couchbase transactions
See original GitHub issueTransaction conversion on read, according to the documentation, should work with this code :
TransactionGetResult getResult = ctx.get(couchbaseClientFactory.getDefaultCollection(), "doc-id");
CouchbaseDocument source = new CouchbaseDocument(getResult.id());
source.setContent(getResult.contentAsObject());
Menu menu = mappingCouchbaseConverter.read(Menu.class, source);
When entity contains a list of nested objects then nested field has incorrect type (ArrayList<HashMap>
) and app crashes with ‘java.lang.ClassCastException: class java.util.HashMap cannot be cast to class com.example.MenuCategory’.
MenuCategory category = menu.getCategories().get(0); // ClassCastException
Document in DB:
{
"_class": "com.example.Menu",
"categories": [
{
"id": "category_1",
"products": [
{
"id": "product_1"
},
{
"id": "product_2"
}
]
}
],
"name": "Menu 1"
}
com.example.Menu:
@Document
public class Menu {
public static final String PREFIX = "menu";
@IdPrefix
private final String prefix = PREFIX;
@Id
@GeneratedValue(strategy = GenerationStrategy.UNIQUE, delimiter = ID_DELIMITER)
private String id;
@Field
private String name;
@Field
private List<MenuCategory> categories;
// getters / setters
}
com.example.MenuCategory:
public class MenuCategory {
private String id;
private List<CategoryProduct> products;
// getters / setters
public static class CategoryProduct {
private String id;
public CategoryProduct() {
}
public CategoryProduct(String id) {
this.id = id;
}
// getters / setters
}
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top Results From Across the Web
Object having id as key-name not getting populated via spring ...
Here user.id is coming as null when fetched from DB. I am using java-sdk-3, spring version 2.3.3.RELEASE, and spring-data-couchbase as 4.0.3.
Read more >Spring Data Couchbase - Reference Documentation
Kotlin classes are supported to be instantiated, all classes are immutable by default and require explicit property declarations to define mutable properties.
Read more >Spring Data Couchbase / Spring Boot: could not get nested list ...
I am new to couchbase and I am encountering an issue on fetching document from couchbase. The nested list of object (List of...
Read more >fix issue with id in nested objects caused by DATACOUCH ...
When a nested document - such as Submission in the User object - contains an 'id', it is also removed from the data....
Read more >spring-projects/spring-data - Gitter
Hello, I'm using spring-data-couchbase's ReactiveCouchbaseRepository and it seems ... public void setValidator(final Validator validator) { this.validator ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ll keep this open for further investigation as to why the documentation doesn’t match - but the following will work.
I realize this was first, but please refer to #1312 as it has more information on it. I’ll make this the ‘duplicate’.