2

I am using spring data rest to create an API over neo4j. I don't want to expose nodeId in my URLs, therefore I have a UUID instead. More info on here:

How can I change neo4j Id to UUID and get finder methods to work?

How can I modify the auto-generated links by the spring-data-rest to reflect the change to UUID instead of nodeId?

Thanks

----UPDATED---

public class CustomBackendIdConverter implements BackendIdConverter {

@Autowired
PracticeAreaRepository practiceAreaRepository;

@Override
public Serializable fromRequestId(String id, Class<?> entityType) {
    return id;
}

@Override
public String toRequestId(Serializable id, Class<?> entityType) {
    if(entityType.equals(PracticeArea.class)) {
        PracticeArea c = (PracticeArea) id;
        return c.getPracticeAreaId().toString();
    }
    return id.toString();
}

@Override
public boolean supports(Class<?> delimiter) {
    return true;
}
}
Community
  • 1
  • 1
Chirdeep Tomar
  • 4,281
  • 8
  • 37
  • 66

1 Answers1

2

Spring Data REST has a BackendIdConverter SPI interface for you implement to translate what's discovered as the identifying part of the URI into whatever you're using in the repository's findOne(…) method.

Simply create an implementation of this interface that does the two-way conversion and register it as Spring bean in your ApplicationContext and it will be picked up by Spring Data REST automatically.

Oliver Drotbohm
  • 80,157
  • 18
  • 225
  • 211
  • Thanks for your reply. I am trying to do what you suggested and using this as a baseline, http://stackoverflow.com/questions/23801575/customizing-hateoas-link-generation-for-entities-with-composite-ids. Throwing errors at PracticeArea c = (PracticeArea) id; Do I need to create other two classes as suggested in that answer, I guess not? – Chirdeep Tomar Feb 09 '15 at 17:06