Scrivio Interview library
DesignPrincipal7 min read · updated 12 November 2026

Integration code across your company converts the same partner XML into domain objects in many different ways, with adapters copied between services. How would you organise mapping code at company scale?

I would separate two layers that are currently mixed: a binding layer that turns partner XML into faithful Java objects, which is shared as a versioned module per partner with standard adapters for dates, money and code lists, and a domain mapping layer, which each service keeps because it reflects that service's own model. Where many services need the same partner data, a central integration service that receives the XML once and publishes clean events is the alternative. The choice weighs coupling: shared libraries spread upgrades, a central service adds latency and needs an owner. Either way, code lists and value mappings are documented in one place and tested with real samples.

Why this question is asked

When several teams integrate with the same partner, each one usually starts by copying the last team's code. A year later there are six versions of the same date adapter, three interpretations of the partner's status codes and a bug that was fixed in one service and lives on in five others. Interviewers ask this question of very senior engineers because the answer is about structure and ownership, not about JAXB itself. In this answer, we will see why copied mapping code goes wrong, separate binding from domain mapping, design shared binding modules, compare them with a central integration service, and set up the shared knowledge that both need.

1Why Copied Mapping Code Goes Wrong

Converting partner XML into domain objects mixes three different kinds of knowledge. The first is the syntax of the partner's format: element names, namespaces, date formats, how amounts are written. The second is the meaning of the partner's values: that status code 07 means 'held for review', or that an empty country field means the home country. The third is our own domain: how a service models a payment or a customer.

Only the third kind genuinely differs between services. The first two are facts about the partner, and they should be the same everywhere. When each service copies and adapts the whole stack, those facts drift. One team fixes the handling of time zones in dates, another adds a new status code, and nobody else hears about it. The real problem is not duplicated code; it is duplicated knowledge with no single owner.

2Separating Binding From Domain Mapping

So the first design move is to split the conversion into two layers. The binding layer is a faithful Java representation of the partner's messages: classes generated from the partner's XSD with xjc, or hand-written DTOs, plus standard adapters that turn the partner's representations into standard Java types, such as LocalDate, a Money value or an enum for a code list. It contains no business decisions. The domain mapping layer takes those binding objects and builds a service's own domain objects, applying that service's rules.

Step throughWhere each kind of knowledge lives
  1. Partner XMLthe partner's format, versioned by the partner
  2. Shared binding module per partnergenerated classes, standard adapters, code lists
  3. Domain mapper in each servicethe service's own rules and model
  4. Service domain modelnever sees partner XML types

4 layers, from the top down. Step through them one at a time.

Partner facts are shared once; domain decisions stay with each service.

3Shared, Versioned Binding Modules

Each partner gets one binding module, for example bank-x-binding, owned by a named team and built in CI from a versioned copy of the partner's XSD. It contains the generated classes, the standard adapters configured through binding files, typed code lists, and tests that unmarshal the partner's real sample messages. Services depend on it like any library, with semantic versioning: a new partner schema version that adds optional elements is a minor release, one that changes or removes elements is a major release.

Java
// bank-x-binding 4.2.0: shared facts about Bank X, no business rules
public enum BankXStatus {
ACCEPTED("01"), REJECTED("02"), HELD_FOR_REVIEW("07");
private final String code;
BankXStatus(String code) { this.code = code; }
public static BankXStatus fromCode(String c) {
return Arrays.stream(values()).filter(s -> s.code.equals(c)).findFirst()
.orElseThrow(() -> new UnknownCodeException("BankXStatus", c)); // never silently null
}
}
// payments-service: domain mapping, owned by this service
PaymentState toDomain(BankXStatusReport r) {
return switch (r.getStatus()) { // BankXStatus, already decoded by the binding module
case ACCEPTED -> PaymentState.SETTLED;
case REJECTED -> PaymentState.FAILED;
case HELD_FOR_REVIEW -> PaymentState.PENDING; // this service's choice, not the partner's fact
};
}

Notice the division of work in the example. The binding module knows that 07 means held for review, which is a fact about the partner. The payments service decides that held for review is PENDING in its own state machine, which another service might map differently. The switch over an enum also means that when the binding module adds a new status, the compiler points at every service that must decide what it means.

4Or a Central Integration Service

The second option moves the binding layer out of the services entirely. A single integration service receives the partner's XML, validates and binds it, and publishes clean, partner-neutral events, for example PaymentStatusChanged on a Kafka topic or a JSON API. Other services consume those events and never see the partner's format. This is attractive when many services need the same partner data, when the partner connection itself is complex, such as certificates, SFTP polling or rate limits, or when the partner should only be called from one place.

Both options have real costs, and the right one depends on how many consumers there are and how much they share. A shared library keeps processing inside each service with no extra network hop, but every schema change means every consuming service must upgrade, and old versions linger. A central service makes change local, since one deployment handles a new schema, but it adds latency and a runtime dependency, and it needs a team that owns it, operates it and answers for its availability. A common pattern is to start with shared binding modules and introduce a central service for a partner once more than a few services consume its data or the connection is hard to run.

Shared binding library versus central integration service
ConcernShared binding moduleCentral integration service
Schema changeevery consumer upgrades the libraryone deployment
Latency and runtimein-process, no extra hopextra hop, must be available
Couplingconsumers coupled to partner typesconsumers see neutral events
Ownershiplibrary maintainera team operating a service
Fits bestfew consumers, simple connectionmany consumers, complex connection

5One Place for Code Lists and Value Mappings

Whichever structure we choose, the knowledge of what partner values mean must live in one place. Code lists, value conventions such as what an empty field means, and the mapping between partner codes and our enums are documented next to the binding code, in the same repository, and changed through review. Each code list is tested with real sample messages from the partner, collected over time from production and certification environments, so that a test fails when a sample contains a value we do not know.

Finally, I would migrate the existing copies step by step rather than in one large rewrite. For each partner, we pick the best of the current implementations as the starting point, extract it into the binding module, compare its output with each service's current code on recorded messages, and move services over one by one. Differences found during the comparison are often the bugs that were fixed in one copy and not the others, and resolving them is a large part of the value.

6Follow-up questions

How do you stop teams from copying again?

By making the shared module the easiest path: published, documented, with a working example, and owned by someone who reviews changes quickly. A static check that flags new XmlAdapter classes for a known partner outside its binding module helps, but a good shared module is what really stops copying.

Who should own a partner binding module?

The team that owns the business relationship or the main integration with that partner, with a named maintainer. Other teams contribute changes through pull requests. Unowned modules decay just like copied code, so the owner is part of the design, not an afterthought.

Should the domain mapping ever be shared too?

Only when services truly share a domain model, in which case they may belong together. Sharing domain mapping across services with different models creates a library that tries to serve everyone's rules and fits nobody.

7Conclusion

In this answer, we saw that copied mapping code fails because it duplicates knowledge about the partner without an owner. We separated a binding layer, which holds the partner's format and value meanings, from domain mapping, which each service keeps. The binding layer can be a shared, versioned module per partner with standard adapters and code lists, or a central integration service that publishes neutral events, and we weighed the upgrade spread of libraries against the latency and ownership needs of a service. In both cases, code lists live in one place and are tested with real samples.

What to say in the interviewAbout 90 seconds aloud

Open with

I would first separate two things that the copied code mixes: facts about the partner and decisions of each service. The binding layer is the partner's facts: classes generated from their XSD, standard adapters for dates, money and code lists, and what each code means.

Then, if they want more

I would put that in one shared, versioned module per partner, owned by a named team, built from a versioned copy of the schema and tested with real partner samples, with semantic versioning for schema changes.

Each service keeps its own domain mapping from those binding objects to its own model, because that is where services legitimately differ; for example, one maps held for review to pending, another to a manual queue.

When many services need the same partner data or the connection is hard to run, I would instead centralise in an integration service that receives the XML once and publishes neutral events.

The trade-off is coupling: a shared library spreads every upgrade to all consumers and old versions linger, while a central service makes changes local but adds latency, a runtime dependency and needs a team to own it.

In either case I want code lists and value mappings documented in one place and tested against real samples, and I would migrate the copies gradually, comparing outputs on recorded messages to find the bugs that were only fixed in some copies.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Integration code across your company converts the same partner XML into domain objects...": https://scrivio-interview-library.netlify.app/java/jaxb/9c506399c1/