0

I have a class called RepositoryConfig.java which extends RepositoryRestConfigurerAdapter. The class has a method

public void configureRepositoryRestConfiguration(RepositoryRestConfiguration conf){
    conf.exposeIdsFor(SuperClass.class);
}

Previous versions of Spring would expose the ids in JSON for all classes that extended the superclass. Now after upgrading to the latest Spring Boot 1.3.2 the id is not exposed for the classes that extend the Superclass. Is there a new way to expose the id for every class extending superclass? Or would I have a line of code that exposes the id for every class that extends superclass?

kryger
  • 12,906
  • 8
  • 44
  • 65
Will Harrison
  • 565
  • 3
  • 8
  • 21
  • http://stackoverflow.com/a/24938519/794088 might help – petey Feb 19 '16 at 20:18
  • @petey I have many classes that extend a superclass that I want to expose the id for. I am wondering if there is a way without having a line of code for each sub class – Will Harrison Feb 22 '16 at 16:55

1 Answers1

0

You can get all entities through the EntityManager and filter them according to your needs:

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurerAdapter;

import javax.persistence.EntityManager;
import javax.persistence.metamodel.Type;

@Configuration
public class RepositoryConfig extends RepositoryRestConfigurerAdapter {

    @Autowired
    private EntityManager entityManager;

    @Override
    public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
        config.exposeIdsFor(
                entityManager.getMetamodel().getEntities().stream()
                .map(Type::getJavaType)
                .filter(SuperClass.class::isAssignableFrom)
                .toArray(Class[]::new));
    }
}

Take a look at this answer to see other options.

lcnicolau
  • 3,252
  • 4
  • 36
  • 53