Delphi XE8 has a bug in tjson.ObjectToJsonObject !

Delphi XE8 has a bug in tjson.ObjectToJsonObject ! 
same source in XE7 marshall correctly,  in XE8 error tkPointer... I Suppose problem is in TObjectList ... i'm just triing now. 

someone have same issue?

Comments

  1. thanks ... :(   ..... maybe superobject resolve ?

    ReplyDelete
  2. but.... embarcadero staff use unit test or not???????

    ReplyDelete
  3. Nothing new here. Just more of the same.

    ReplyDelete
  4. This isn't a bug in ObjectToJsonObject. That works as designed. The problem is that you should not expect ObjectToJsonObject to perform magic. Of course, the pitiful Emba documentation is culpable.

    ReplyDelete
  5. David Heffernan At its current price point I can understand that people expect magic from XE8...

    ReplyDelete
  6. David Heffernan , tObjectList marshalling is an embarcadero function since some years ... ...  is not "magic" , it's a standard!
    btw, yes, the problem is in generics not in tjson

    ReplyDelete
  7. Diego Rigoni No. The problem is that you have unrealistic expectations of ObjectToJsonObject. It doesn't do what you think it does. 

    By magic I mean that you are hoping that ObjectToJsonObject is able to work out which fields to serialize, and which to ignore. And there's no way for it to do so. It appeared to work for you in previous versions, but that was an illusion.

    ReplyDelete
  8. well, i still use XE7 and have my nice expectations!  =P  ... until bug fix!

    ReplyDelete
  9. Diego Rigoni Consider this program:

    {$APPTYPE CONSOLE}

    uses
      REST.Json,
      System.Generics.Collections;

    var
      List: TList;

    begin
      List := TList.Create;
      List.Capacity := 4;
      List.Add(42);
      Writeln(TJson.ObjectToJsonString(List));
      Readln;
    end.

    And the output from XE7 is:

    {"items":[42,0,0,0],"count":1,"arrayManager":{}}

    I'm sorry, but that is not how what is essentially an array of length 1 should be serialized. The correct serialization should be, perhaps:

    {"items":[42]}

    The real problem here is that you should not be expecting low-level framework to be able to serialize arbitrary types. ObjectToJsonString has never been expected to serialize complex types like TList. It just so happened that you have got away with doing just that up until now.

    ReplyDelete
  10. yes, i see there's some "dirty" infos , but for my purpose is not important ;)

    read this:
    http://www.danieleteti.it/how-to-serialize-a-tlist-of-objects-with-delphi/

    ReplyDelete
  11. The framework is capable of that because you can register handlers for types. The problem is that TJSON creates an instance internally and has no way of registering any global handlers for built-in types.
    Also if they would have moved the special attributes for JSON serialization (where you can exclude members) into some base unit of the RTL they could have used that throughout their classes.

    ReplyDelete
  12. "yes, i see there's some "dirty" infos , but for my purpose is not important ;)"

    Er, yes, it is important. It's the crux of the matter. It's clear that you just want magic to be performed and you aren't listening to what we are saying. Good luck!

    ReplyDelete
  13. David Heffernan You do know that the entire REST library uses TJSON.ObjectToJsonObject, right? It doesn't fing matter if the mechanism underneath is somewhat broken and serializes arrays wrong. It worked and now it does not. That's all that matters. Oh, and even if it worked to serialize a list properly it broke compatibility between <XE8 and XE8 because the JSON now looks different.

    ReplyDelete
  14. +Stefan It's the REST implementation that is broken. It's been broken all the time. Broken by poor design.

    ReplyDelete
  15. nope, cantù says they are working on it ...

    ReplyDelete
  16. ahahah! we hope!
    for now we use other serialization library (objectmappers inside dmvcframework
    )

    ReplyDelete
  17. That sounds like a much more sensible approach than expecting TList to be serializable, something that it has never purported to be. Then again, if it is as Stefan says, that the problem is that the Emba REST code is abusing TList, then yes the problem is with Emba's code. But in that case the problem is in the REST code rather than ObjectToJsonObject.

    ReplyDelete
  18. I am having the same problem , any solution?

    ReplyDelete
  19. Download dvmc framwork by Daniele teti. There's a fantastic mapper class

    ReplyDelete

Post a Comment