[MDSAL-39] Provide utility service which will convert Java Generated DTO to JSON Created: 14/Jul/14  Updated: 09/Jan/24

Status: Confirmed
Project: mdsal
Component/s: Binding API, Binding runtime
Affects Version/s: None
Fix Version/s: 14.0.0, 13.0.1

Type: New Feature
Reporter: Tony Tkacik Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: pick-next, pt
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Operating System: Windows
Platform: PC



 Description   

See comments below for some amount of guidance. As a first cut, we want to transcode information based on InstanceIdentifier + DataObject. The implementation needs to use mdsal-binding-dom-codec-api facilities to transcode the DataObject to a NormalizedNode and then turn that into a JSON string.

Once we have a prototype we can then evolve it to more effecient transcoding, including stream setup pipelines.



 Comments   
Comment by Tony Tkacik [ 16/Jul/14 ]

What you want to do is implement an service with signature

JSONCodec extends BindingCodec<String,DataObject> {

String serialize(DataObject);
DataObject deserialize(String);
}

Which will:
use BindingIndependentMappingService to get conversion from Binding DTOs
to DOM nodes and then integrate with JSON Codec (which is currently in sal- restconf-connector and should be probably externalized to separate bundle),
which is responsible for writing DOM nodes to JSON.

So basicly your service is integration of two services:
Binding -> DOM (BindingIndependentMappingService)
DOM -> JSON (which should have stream api, and maybe support multiple writer implementations (GSon, Jackson).

BindingIndependentMappingService is available via Config subsystem and OSGI registry, but not directly via MD-SAL.

Comment by Tony Tkacik [ 17/Jul/14 ]

DOM to XML is converted using XMLDocumentUtils and same utility functions
could be found in restconf-util in YANGTOols project.

Comment by Mina [ 10/Aug/14 ]

(In reply to Tony Tkacik from comment #1)
> What you want to do is implement an service with signature
>
> JSONCodec extends BindingCodec<String,DataObject>

{ > > String serialize(DataObject); > DataObject deserialize(String); > }

>
> Which will:
> use BindingIndependentMappingService to get conversion from Binding DTOs
> to DOM nodes and then integrate with JSON Codec (which is currently in sal-
> restconf-connector and should be probably externalized to separate bundle),
> which is responsible for writing DOM nodes to JSON.
>
> So basicly your service is integration of two services:
> Binding -> DOM (BindingIndependentMappingService)
> DOM -> JSON (which should have stream api, and maybe support multiple writer
> implementations (GSon, Jackson).
>
> BindingIndependentMappingService is available via Config subsystem and OSGI
> registry, but not directly via MD-SAL.

The following service:
DOM -> JSON

should be implemented getting idea from XMLDocumentUtils.

And also JsonCodec has the following two parts when serializes:

  • Binding -> DOM (BindingIndependentMappingService)
  • DOM -> JSON (JSONDocumentUtils)

public class JSONCodec implements BindingCodec<String,DataObject> {

private BindingIndependentMappingService mappingService;

public String serialize(DataObject dataObject)

{ CompositeNode node = mappingService.toDataDom(dataObject); ..... }

public DataObject deserialize(String str)

{ ..... }
Comment by Mina [ 10/Aug/14 ]

(In reply to Mina Aslani from comment #3)
> (In reply to Tony Tkacik from comment #1)
> > What you want to do is implement an service with signature
> >
> > JSONCodec extends BindingCodec<String,DataObject>

{ > > > > String serialize(DataObject); > > DataObject deserialize(String); > > }

> >
> > Which will:
> > use BindingIndependentMappingService to get conversion from Binding DTOs
> > to DOM nodes and then integrate with JSON Codec (which is currently in sal-
> > restconf-connector and should be probably externalized to separate bundle),
> > which is responsible for writing DOM nodes to JSON.
> >
> > So basicly your service is integration of two services:
> > Binding -> DOM (BindingIndependentMappingService)
> > DOM -> JSON (which should have stream api, and maybe support multiple writer
> > implementations (GSon, Jackson).
> >
> > BindingIndependentMappingService is available via Config subsystem and OSGI
> > registry, but not directly via MD-SAL.
>
>
> The following service:
> DOM -> JSON
>
> should be implemented getting idea from XMLDocumentUtils.
>
> And also JsonCodec has the following two parts when serializes:
>
> - Binding -> DOM (BindingIndependentMappingService)
> - DOM -> JSON (JSONDocumentUtils)
>
> public class JSONCodec implements BindingCodec<String,DataObject> {
>
> private BindingIndependentMappingService mappingService;
>
> public String serialize(DataObject dataObject)

{ > CompositeNode node = mappingService.toDataDom(dataObject); > ..... > }

>
> public DataObject deserialize(String str)

{ > ..... > }

Is this how suggested for the bug to be fixed?

Comment by Robert Varga [ 24/Jul/21 ]

Yes, although the IO part of it should provide integration with IO, i.e. write to OutputStream, etc.

Generated at Wed Feb 07 20:08:29 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.