Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Struggling to see how to create json with fields #13

Open
AwesomeBiscuitBadger opened this issue Feb 15, 2021 · 0 comments
Open

Struggling to see how to create json with fields #13

AwesomeBiscuitBadger opened this issue Feb 15, 2021 · 0 comments

Comments

@AwesomeBiscuitBadger
Copy link

AwesomeBiscuitBadger commented Feb 15, 2021

Hi,

I have been trying to use json.adb in the samples directory to write my own serializers, and I have a couple of issues:

  1. Proxy functions with vector mappers -- can't get this to work. I have a record where one of the items is a vector and I can't work out what should go in the proxy field as the vector mappers don't have a Set_Member.
  2. Producing a json string from a vector of records of the form {"field1": [{"a": 1,"b":2}, {"a: 5, "b":6}]}. For some reason I can't get the output string to have the field names in, just lists the field content. What am I doing wrong there?
  procedure Print (P : in My_Type.Cursor);
    procedure Print (P : in My_Element);

    procedure Print (P : in My_Element) is
    begin
   Ada.Text_IO.Put_Line ("A       : " & P.A);
   Ada.Text_IO.Put_Line ("B : " & P.B);
    end Print;

    procedure Print (P : in My_Type.Cursor) is
    begin
       Print (My_Type.Element (P));
    end Print;



`        declare
          Buffer : aliased Util.Streams.Buffered.Output_Buffer_Stream;
          Print  : aliased Util.Streams.Texts.Print_Stream;
          Output : Util.Serialize.IO.JSON.Output_Stream;
          begin
              -- Convert to external facing type for conversion to json out to HTTP
          My_Type.Set_Type (To => List, From => Internal_Element);
          Buffer.Initialize (Size => 10000);
          Print.Initialize (Buffer'Unchecked_Access);
          Output.Initialize (Print'Unchecked_Access);
      Ada.Text_Io.Put_Line("Second Marker");
          Output.Write ("{""list"":");
          Internal_Vectors_Mapping.Write (Output, List);
      Output.Write ("}");

          Ada.Text_IO.Put_Line ("IO:");
          Ada.Text_IO.Put_Line (Util.Streams.Texts.To_String (Print));
       end;
    end;` 

Obviously there is a chance I'm doing this all wrong, in a fundamental way. I want to serialize my type to output it to json and then out to other executables, at which point it'll be deserialized and brought back into the internal code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant