0

I have to systems:

  • System A is a legacy system and cant be programmed
  • System B has to consume objects from System A via REST

System A has the superclass Customer and the subclasses Private Customer, Business Customer and Government Customer. Each of the subclasses inherit basic attributes from Customer and extends the their own attributes.

System A sends a Customer as JSON to System B. System B doesnt know if the JSON is a Private Customer, Business Customer or a Government Customer. But it needs to create Java Objects out of them into the right kind of Customer.

One solution could be to make a case destinction. If class specific attributes are present or not. But none of the values are obligatory. Plus, I want some sort of blueprint and creating such specific case destinctions are not a good programming design.

Is there a best practice for that?

1 Answers1

0

If you cannot handle in your new system B Customer class which has all possible fields and you need/ want to differ between Private Customer, Business Customer and Government Customer then I think the best it will be to make 3 different REST endpoints in A system which return the 3 different classes as result types. If you want you can preserve in the System B the same structure with parent child classes just when you are requesting the objects from system A you will know what A will return to you as a type.

Example for method signatures for endpoints in project A:

Collection<PrivateCustomer> getPrivateCustomers(Filter filter)

Collection<BusinessCustomer> getBusinessCustomers(Filter filter)

Collection<GovernmentCustomer> getGovernmentCustomers(Filter filter)

I hope it helps.

Level_Up
  • 789
  • 5
  • 19
  • 1
    Thank you very much for your answer. Yeah, that is one way to solve it but I thought more of something that can actually parse the structure of the incoming DTO and decide, what kind of customer is incoming. I thought someone might have some sort of plugin/extension/library for that. – TheAmygdala Apr 04 '20 at 10:52
  • You are welcome. Yes it will be interesting to see other options. – Level_Up Apr 05 '20 at 23:01