Skip to content

Hal rendering Jackson2HalModule for custom type is not working #1259

Open
@yvoroshilov

Description

@yvoroshilov

Http converter renders data as regular json instead (i.e. "links" instead of "_links"). If set jackson module to collectionjson or uber everything seems to work fine.
Configuration

@Configuration
public class ContactDirMediaTypeConfiguration implements HypermediaMappingInformation {

  @Override
  public Module getJacksonModule() {
    return new Jackson2HalModule();
  }

  @Override
  public List<MediaType> getMediaTypes() {
    return MediaType.parseMediaTypes("application/vnd.contactdir.v1+json, application/hal+json");
  }
}

configuration provider

public class ContactDirMediaTypeConfigurationProvider implements MediaTypeConfigurationProvider {

  @Override
  public Class<? extends HypermediaMappingInformation> getConfiguration() {
    return ContactDirMediaTypeConfiguration.class;
  }

  @Override
  public boolean supportsAny(Collection<MediaType> mediaTypes) {
    return true;
  }
}

controller

@RestController
@RequestMapping("/api")
public class ContactListController {
  @GetMapping(path = "/contacts",
      produces = {"application/vnd.contactdir.v1+json", "application/hal+json"})
  public ResponseEntity<ContactDto> getAllContacts() {
    ContactDto dto = new ContactDto().setName("dfsfdsfsdf");
    dto.add(linkTo(ContactListController.class).withSelfRel());
    return new ResponseEntity<>(dto, HttpStatus.OK);
  }
}

Project reproducing the problem
Is it a bug or (what is more possible) did I miss something?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions