1

My problem is a bit complicated. It is as follows: I get via HTTPClient answers from the (in my case) "Slack"-API. This data is sent as JSON, so I deserialize it into the fitting objects(classes) I wrote for this. Until now I just handled the data directly from these containers. But my boss now said, "what if Slack changes something and these things are called differently all of a sudden? - We need an independent container that provides this received data, always under the same names! So when we implement your .dll we never have to care about these changes, only you have to refactor/rename your classes/members". I totally understand his point. But I can not figure out how I would do this. As I said, these containers are classes I wrote, and when I want to create another container that can take the wanted data and save it, I always stumble over the fact that I cannot convert these object types to the other object types. How could I do that? I tried every way I could imagine and now I am stuck...

Does anybody have an idea or just a tip? Maybe there is a far easier solution to my problem and I can not see it. That's why I wrote what my boss wants from me in this case.

I am sorry for the title of this question, I didn't know what else to write.

Maksym Labutin
  • 561
  • 1
  • 8
  • 17
Fabian Held
  • 373
  • 1
  • 6
  • 17
  • Why does your boss think it is better to add layer of complexity? When the Slack API changes you have to adapt. No matter if it is in the current code, or in the added mapper/wrapper. What about YAGNI? – Markus Deibel Mar 12 '19 at 13:37
  • You Ain't Gonna Need It. If they add a field, you have to add it in the wrapper AND in your lib. Same goes for a deletion. The only advantage you have here is when Slack changes the name of a field and I think this is highly unlikely. – Markus Deibel Mar 12 '19 at 13:47

1 Answers1

3

You can have slack related property names defined via JsonProperty atttribute. This way you only need to change few strings instead of changing property names and refactoring parts of applications (including maybe UI if you send those objects directly to UI)

using Newtonsoft.Json;
[JsonProperty(PropertyName = "SlackPropName")]
public string MyPropName { get; set; }
  • God damn it... :) sorry for cursing, but that is so obvious it hurts xD I already used the JsonProperties in my first versions of my code... then I thought I don't need them, deleted them and forgot about them. But well, sure they hold the easiest answer to my question. Thank you very much! Have a nice day! – Fabian Held Mar 12 '19 at 13:47