Made my JSON interceptor demo public.

Made my JSON interceptor demo public.
Now you can save your enum and sets to JSON, with customized output to boot!


http://chuacw.ath.cx/blogs/chuacw/archive/2017/12/11/persisting-enumeration-and-sets-to-json.aspx

Comments

  1. FWIW I would have used a solution with const array over the enum to specify the names because that will give you a compile error when someone extends the enum. With your solution you will have to look around the code finding the spot where you have to put a new value.

    ReplyDelete
  2. I don't care about System.JSON or REST.JsonReflect

    I just pointed out a possible defect in your design causing hard to find bugs

    ReplyDelete
  3. Try doing that first before suggesting it.

    ReplyDelete
  4. Pointing out a bug or design issue does not require to fix that bug or design issue. Again, if you think it is fine as you did it - please, it is your code and you can do whatever you want. You are free to ignore my suggestion but don't react like that please.

    ReplyDelete
  5. Your refusal to try putting attributes on enumerations is interesting... if you've tried it, you wouldn't be suggesting it. Don't react before you try.

    ReplyDelete
  6. If you've tried, you would know it's impossible to place attributes on enumerations and get them back in Delphi. Your insistance on not trying and finding out for yourself that it's not possible to do so... that was my first design...

    That you didn't try and keep insisting... shows some level of hubris.

    ReplyDelete
  7. I can only imagine in future that Stefan will not even bother trying to help you with any problems you may face... believe me, that would be a massive loss on your part.

    I also now have no interest in trying out your code in case I spot something and get a similar response.

    ReplyDelete
  8. CHUA Chee Wee
    Read my comment again, I did not say anything about putting attributes on enums (I know that it does not generate attribute RTTI and I would not even do that because that would bind JSON serialization logic to the type). I said that I would use a const array of an enum of string

    const FunnyEnumNames: array[TFunnyEnums] of string = ('High...lander!', 'Galaxy Fish???', 'James Bond!');

    And then somehow use that in the interceptor for TFunnyEnums - yes you need to write some code for them and cannot just annotate them with attributes. If we could use all consts (not just those that are "real" consts but not write protected variables in disguise) on attributes.

    Now if anyone adds a value to TFunnyEnums you get a compile error telling you that an element is missing. With your approach you will only ever notice when you serialize something and it either raises an exception or writes something wrong (I did not check all the code if there any other checks than the assert)

    ReplyDelete
  9. CHUA Chee Wee I suggest you to listen more closely
    to what other people say before attacking them. Stefan Glienke spent his time when reading your code, spotted real design flaw, even suggested how it could be easily fixed and yet you still offend him? It looks silly and very childish to me.

    ReplyDelete
  10. Stefan Glienke I tried your suggestion:

    [
    EnumAs(FunnyEnumNames[TFunnyEnums.Highlander]),
    EnumAs(FunnyEnumNames[TFunnyEnums.GalaxyFish]),
    EnumAs(FunnyEnumNames[TFunnyEnums.TomorrowNeverComes])
    ]
    TFunnyEnumInterceptor2 = class(TEnumInterceptor)

    Got Error E2026 (Konstantenausdruck erwartet) 3 times.

    ReplyDelete
  11. Gustav Schubert That is not what I suggested

    ReplyDelete
  12. Is there a reason to not use the actual enum names?

    ReplyDelete
  13. Lars Fosdal Interoperability with JSON from web site APIs

    ReplyDelete

Post a Comment