How to create Thymeleaf converter with Mono object

Viewed 143

I need to create convereter from string to object.

@Component
public class PropertyConverter implements Converter<String, PropertyShop> {
    @Autowired
    PropertyShopService propertyShopService;

    @Override
    public PropertyShop convert(@NotNull String id) {
        long idBD = Long.parseLong(id);
      
        return propertyShopService.getPropertyById(idBD); // Mono<PropertyShop>
  
}

But from propertyShopService I received Mono<PropertyShop>.

1 Answers

Although this is not a good way in my opinion and I'll prefer returning Mono instead of extracting PropertyShop from Mono. But if you really need to do that you can use

return propertyShopService.getPropertyById(idBD).block();

for more details you can check this Link

Related