Skip to Content
0
Former Member
Jul 19, 2016 at 03:13 PM

Returning Jackson2 Annotated Objects from an OCC Addon Controller

549 Views

Hi, we are currently using Hybris 5.7 and are trying to return Jackson2 Annotated POJOs from a controller roughly similar to the following stripped down example controller which is located in an occ addon extension (acceleratoraddon/web):

 import com.fasterxml.jackson.databind.ObjectMapper;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 
 @Controller("ociProductsController")
 @RequestMapping(value = "/{baseSiteId}/oci/products")
 public class OciProductsController {
     @Resource
     private OciProductsFacade ociProductsFacade;
 
     @ResponseStatus(value = HttpStatus.OK)
     @RequestMapping(value = "/{productId}", method = RequestMethod.GET)
     @Secured("ROLE_OCIINTERFACESGROUP")
     public ResponseEntity<OciProductWsDTO> findProductById(@PathVariable final String productId) {
         final Optional<Map<String, Object>> result = this.ociProductsFacade.getProductForCode(productId);
         ObjectMapper objectMapper = new ObjectMapper();
         return result
                 .map(data -> objectMapper.convertValue(data, OciProductWsDTO.class))
                 .map(ResponseEntity::ok)
                 .orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND));
     }
 
 }

However when trying to call the route it seems that all Jackson annotations are ignored and it serializes the POJO only based on its attributes, e.g.

 import javax.annotation.Generated;
 import com.fasterxml.jackson.annotation.JsonInclude;
 import com.fasterxml.jackson.annotation.JsonProperty;
 import com.fasterxml.jackson.annotation.JsonPropertyOrder;
 
 @JsonInclude(JsonInclude.Include.NON_NULL)
 @Generated("org.jsonschema2pojo")
 @JsonPropertyOrder({
     "ProductClassification_ResellerShop",
 })
 public class OciProductWsDTO {
     @JsonProperty("ProductClassification_ResellerShop")
     private Boolean productClassificationResellerShop;
 
     @JsonProperty("ProductClassification_ResellerShop")
     public Boolean getProductClassificationResellerShop() {
         return productClassificationResellerShop;
     }
 
 }

is being serialized as:

 {"productClassificationResellerShop": true}

and not as expected as:

 {"ProductClassification_ResellerShop": true}

From what we could find out so far only JaxB annotations are supported. How do we add Jackson2 Annotation Serialization support?