'Getting only values instead of keys and values in JSON response in spring boot while calling Store procedure

@RestController
public class SpController {
    @RequestMapping(value = "/getMicrosectorTiers", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<?> getGRCSHierarchy_MicroSectorTiers() throws Exception{
        try {
            List<GRCSHierarchy_MicroSectorTiers> dataResulat= 
               grcsHierarchyMicroSectorTiers_SP_Service.getGRCSHierarchy_MicroSectorTiers();
            if (dataResulat.isEmpty()) {
                return new ResponseEntity<>(HttpStatus.NO_CONTENT);
            }
            return new ResponseEntity<>(dataResulat, HttpStatus.OK);
        } catch (Exception e) {
            return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }
}

Repo

    @SuppressWarnings("unchecked")
    public List<GRCSHierarchy_MicroSectorTiers> getGRCSHierarchy_MicroSectorTiers()throws Exception {
        List<GRCSHierarchy_MicroSectorTiers> list = new ArrayList<GRCSHierarchy_MicroSectorTiers>();
        StoredProcedureQuery query =null;
        try {
             query = entityManager.createStoredProcedureQuery("usp_GRCSHierarchy_GetMicroSectorTiers");
            query.execute();
            list = query.getResultList();
        }catch (Exception e) {
            throw new RuntimeException(e.getMessage());
        }
        finally {
            try {
                query.unwrap(ProcedureOutputs.class).release();
            } catch (Exception e) {
                throw new RuntimeException(e.getMessage());
            }
        }
        return list;
    }

Pojo

@MappedSuperclass
@SqlResultSetMapping(name = "GRCSHierarchy_MicroSectorTiers", classes = @ConstructorResult(targetClass = GRCSHierarchy_MicroSectorTiers.class, columns = 
{ @ColumnResult(name = "GRCSNodeId", type = String.class),@ColumnResult(name = "GreenTier", type = String.class) }))
public abcPjo{
GRCSNodeId
GreenTier
}

Output [ [ "EG.01.0", 3 ], [ "EG.01.1", 2 ] ] Expected Output {"GRCSHierarchy_MicroSectorTiers":[ { "GRCSNodeId": "EG.01.0", "GreenTier": 3 }, { "GRCSNodeId": "EG.01.0", "GreenTier": 3 }, { "GRCSNodeId": "EG.01.0", "GreenTier": 3 } ] }



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source