I noticed how our codebase contains multiple versions of the same method, which unmarshalls the inbound byte-stream into java objects and that the only difference between the current and previous version is the one variable change. There are roughly 17 versions, which are all chosen based on one big switch case. Similar differences occur between any version, where a parameter has changed, and it has caused the whole method to be duplicated.
Now the way I understand it is that parameters read from the byte stream come in order as they were placed there and any unmarshaller would need to be aware of the order in which the elements were added to the byte stream. Any changes to the order of the byte stream and a whole method is rewritten and new version added. This leads to significant code duplication as majority of the parameters within the method remain unchanged.
My question is whether this is the standard way of implementing this or is there some pattern/design principle which could be followed which would not lead to such duplication for reading elements from the byte stream. From architecture perspective, the system is a big monolith.