vendredi 30 décembre 2016

Change variable type in Java code

I need to change a type of ID variable (represents ID of the database entry) from int to String because of the move from SQL database to NoSQL and the id is now a UUID represented as a String. In IntelliJ I can do "Type Migration" - it's pretty good, but it does not obviously fix all the issues and uses of that variable (there is int to String conversions, things like that). It's a lot of changes that are very error prone.

Is there a design pattern or a design technique that might be helpful in this situation besides going and changing all affected code by hand? I thought about converting UUID into a number, but it's 128 bits and won't fit into any primitive in Java, so I'd still need to change the type in the end. Maybe there is a mapping of some sort I can do or an adapter?

A bit of background: it's a desktop application that receives JSON messages from the API. The id of an entry used to be an int, but we are changing the API and now it's a String. I was working on updating the API controller part of the desktop application as I ran into this problem.

Here is the JSON: this output is produced by the normalizr node module from RethinkDB.

{
 "entities":{  
      "contacts":{  
         "8df9e9fb-df15-4070-b8fe-a6255526034d":{  
            "firstName":"<redacted>",
            "id":"8df9e9fb-df15-4070-b8fe-a6255526034d",
            "lastName":"<redacted>",
            "phoneNumber":"<redacted>"
         },
         "434d9b5f-c845-45f3-8c2a-65a0d5851410":{  
            "firstName":"<redacted>",
            "id":"434d9b5f-c845-45f3-8c2a-65a0d5851410",
            "lastName":"<redacted>",
            "phoneNumber":"<redacted>"
         },

      }
}

Aucun commentaire:

Enregistrer un commentaire