How to convert int Mongodb type to boolean in Spring Boot application

Viewed 281

Seeing error in logs "ConverterNotFoundException: No converter found capable of converting from type [java.lang.Integer] to type [boolean]" when browse http://localhost:8080/inventory

My class is like:

class Item{
@Id
private String id;
...
@Field(value="is_on_sale")
private boolean isOnSale //<--this
}

My mongo collection appears like:

-_id   1
...
-is_on_sale    0

I don't have any special MongoDb config except for my repository like:

@RepositoryRestResource(collectionResourceRel = "inventory", path = "inventory")
public interface PurchaseRepository extends MongoRepository<Item, String> {
}

It's a bare-bones app having only the following dependencies:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>

I've read around I need to use a custom converter, but that would imply needing a custom mongodb configuration, is that correct / all that is needed? I.e. am I on the right track or is it simpler than this to resolve this issue?

0 Answers
Related