You seem to be asking for two different things here:
changing the values of some fields
Are you referring to how you need to normalize values' formattings (
) or possibly even data types here (
)? If so, I'll suggest creating a conversion class to handles these, so that you can safely eliminate both the conversion and API pollutions within your class.
making changes such that the new file complies to older schema
Wells, serialization libraries and how they handle schema resolution came to my mind immediately, such as how Apache Avro
does it... If you can consider your objects/data files (hmms a bit of a stretch though for the latter) to be handled as a form of serialization, then these libraries are definitely worth a look here, because the problem is most likely solved for you
. For the full low-down on schema resolution comparisons, this article
is a great, if slightly overwhelming, read too.
edit Given the risk of link rot, I'll just quote the relevant parts of the article here...
- Then you find that people are stuffing all sorts of random fields into their objects, using inconsistent types, and you’d quite like a schema and some documentation... hey, if you had a schema, you could avoid storing objects’ field names, and you could save some more bytes!
Once you get to the fourth stage, your options are typically Thrift, Protocol Buffers or Avro. All three provide efficient, cross-language serialization of data using a schema, and code generation for the Java folks.
In real life, data is always in flux. The moment you think you have finalised a schema, someone will come up with a use case that wasn’t anticipated, and wants to “just quickly add a field”. Fortunately Thrift, Protobuf and Avro all support schema evolution: you can change the schema, you can have producers and consumers with different versions of the schema at the same time, and it all continues to work. That is an extremely valuable feature when you’re dealing with a big production system, because it allows you to update different components of the system independently, at different times, without worrying about compatibility.