Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java @带Spring PagedResources的JsonView_Java_Spring_Spring Mvc_Jackson - Fatal编程技术网

Java @带Spring PagedResources的JsonView

Java @带Spring PagedResources的JsonView,java,spring,spring-mvc,jackson,Java,Spring,Spring Mvc,Jackson,我用Rest控制器暴露了一个pojo。我需要为一个GET请求隐藏一些属性,所以我决定使用jackson的注释@JsonView。我找不到使用@JsonView和PagedResources的任何方法 这是我的pojo: public class Pojo { interface RestrictedPojo {} interface AllPojo extends RestrictedPojo {} @Id @JsonView(RestrictedPo

我用Rest控制器暴露了一个pojo。我需要为一个GET请求隐藏一些属性,所以我决定使用jackson的注释@JsonView。我找不到使用@JsonView和PagedResources的任何方法

这是我的pojo:

public class Pojo {

     interface RestrictedPojo {}
     interface AllPojo extends RestrictedPojo {}

     @Id
     @JsonView(RestrictedPojo.class)
     private String identifier;

     @JsonView(AllPojo.class)
     private String someproperty;

     /**
      * Property I want to hide
      */
     @JsonView(RestrictedPojo.class)
     private String someHiddenProperty;
}
这是我的控制器:

@RepositoryRestController
@RequestMapping(value = "/pojo")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class PojoController {

    private final PojoService pojoService;

    private final IdentityUtils identityUtils;

    private final PagedResourcesAssembler<Pojo> pagedResourcesAssembler;

    @PreAuthorize("hasRole('SOME_ROLE')")
    @GetMapping
    @JsonView(Pojo.RestrictedPojo.class)
    public ResponseEntity<PagedResources<Resource<Pojo>>> getAllRestrictedPojos(final Pageable pageable) {
        final Page<Pojo> allPojo = pojoService.getAllRestrictedPojos(pageable);
        final PagedResources<Resource<Pojo>> resources = pagedResourcesAssembler.toResource(allPojo );
        return ResponseEntity.ok(resources);
    }

    @PreAuthorize("hasRole('SOME_ROLE')")
    @GetMapping
    @JsonView(Pojo.AllPojo.class)
    public ResponseEntity<PagedResources<Resource<Pojo>>> getAllPojos(final Pageable pageable) {
        final Page<Pojo> allPojo = pojoService.getAllRestrictedPojos(pageable);
        final PagedResources<Resource<Pojo>> resources = pagedResourcesAssembler.toResource(allPojo );
        return ResponseEntity.ok(resources);
    }
}
@RepositoryRestController
@请求映射(value=“/pojo”)
@RequiredArgsConstructor(onConstructor=@_u(@Autowired))
公共类控制器{
专用最终PojoService PojoService;
私人最终身份直到身份;
专用最终页面数据源汇编页面数据源汇编;
@预授权(“hasRole('SOME_ROLE'))
@GetMapping
@JsonView(Pojo.RestrictedPojo.class)
公共响应全部受限POJO(最终可分页){
最终页面allPojo=pojoService.getAllRestrictedPojos(可分页);
final PagedResources resources=pagedResourcesAssembler.toResource(allPojo);
返回ResponseEntity.ok(资源);
}
@预授权(“hasRole('SOME_ROLE'))
@GetMapping
@JsonView(Pojo.AllPojo.class)
公共响应getAllPojos(最终可分页){
最终页面allPojo=pojoService.getAllRestrictedPojos(可分页);
final PagedResources resources=pagedResourcesAssembler.toResource(allPojo);
返回ResponseEntity.ok(资源);
}
}
我没有编写特定的配置,它是一个基本的spring启动应用程序

有人能帮忙吗


谢谢

当您将
@JsonView(RestrictedPojo.class)
放在字段上时,您将它放在了json中。如果你想隐藏这个字段,你不需要给他加注释。也许不清楚。我需要实施此处解释的解决方案: