web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Custom JSON Service: Issue Extending Data Contract

(2) ShareShare
ReportReport
Posted on by 272

Hello,

I’m currently facing an issue while working on a custom JSON service within Dynamics 365 for Finance and Operations, and I’m seeking your support.

My goal is to create a generic service, where i can using extension add more fields based on customers needs.

I’ve successfully created a custom JSON service that accepts an input data contract. However, when I extend this data contract with a subclass to include additional fields, the new values are not being read correctly, even though the JSON payload is structured properly and includes the additional fields.

This is the JSON:

{
    "REQUEST":
    {
        "DATA":
        [
            {"A": "123", "B": "XXX", "C": "999"},
            {"A": "456", "B": "YYY", "C": "888"}
        ]
    }
}

Here’s a brief outline of the problem:

  • This is the service method:
public AAAResponse post(
     AAARequest REQUEST)
{
    AAAResponse response = new AAAResponse();   
    List data = REQUEST.parmDATA();
 
..
 
    return response;
}
  • This is the AAARequest data contract class, it contains a list of AAAData class
[DataContractAttribute]
public class AAARequest
{
    List data = new List(Types::Class);
    [DataMemberAttribute("DATA"),
        DataCollectionAttribute(Types::Class, classStr(AAAData)),
        AifCollectionType("_DATA", Types::Class, classStr(AAAData)),
        AifCollectionType("return", Types::Class, classStr(AAAData))]
    public List parmDATA(List _DATA = data)
    {
        data = _DATA;
        return data;
    }
}
 
This is the contract where i define fields, in base classe only "A"
 
public class AAAData
{
    str a;
    [DataMemberAttribute("A")]
    public str A(str _a = a)
    {
        a = _a;
        return a;
    }
}
 
  • I’ve created in another model a class that extending the base contract to add new fields, in this case "C".
[ExtensionOf(classStr(AAAData))]
public final class AAAData_Extension
{
    public str c;
    [DataMemberAttribute("C"), Newtonsoft.Json.JsonExtensionDataAttribute]
    public str C(str _c = c)
    {
        c = _c;
        return c;
    }
}
  • Only the fields from the base contract are being read, while the fields from the extended contract are ignored.

The service reads the BaseField correctly, but the ExtendedField is not being processed, even though it is present in the JSON payload.

My opinion is the JSON deserialization for some kind of reason does not "know" extension fields

Has anyone encountered a similar issue when extending a data contract in a custom service?

Are there any specific steps or configurations I need to ensure for the service to recognize the extended data contract fields?

Any guidance or suggestions would be greatly appreciated!

Thank you in advance for your help!

Best regards,
Diego

I have the same question (0)
  • Layan Jwei Profile Picture
    8,118 Super User 2025 Season 2 on at
    Hi,

    First of all no need to say     List data = new List(Types::Class); in the AAARequest class
    [DataContractAttribute]
    public class AAARequest
    {
        List data;  // no need to initialize it
        [DataMemberAttribute('DATA'),
            DataCollectionAttribute(Types::Class, classStr(AAAData)),
            AifCollectionType("_data", Types::Class, classStr(AAAData)),
            AifCollectionType("return", Types::Class, classStr(AAAData))]
        public List parmData(List _data = data)
        {
            data = _data;
            return data;
        }
    } 

    class AAAData needs to have data contract attribute, which is missing from ur end
    [DataContractAttribute]
    public class AAAData
    {
        str a;
        [DataMemberAttribute('A')]
        public str parmA(str _a = a)
        {
            a = _a;
            return a;
        }
    }

    Now for the extension class, why did you add "Newtonsoft.Json.JsonExtensionDataAttribute"? did u try without it?

    I'm not saying that my points will fix the issue as I didn't try to add a contract via extension -- but definitely adding [DataContractAttribute] to AAAData class is needed

    so let's see what happens after you do that

    ​​​​​​​Also can you please show us the full code for the post method?

    Thanks,
    Layan Jweihan
     
  • Diego Mancassola Profile Picture
    272 on at
    Hello Layan, i have try your suggestions but din't works.
     
    1. Removed JsonExtensionDataAttribute (Was mine try but nothing changed)
    2. Removed inizialization of List
    3. DataContractAttribute was already present, my mistake during create the community post
     
    Here the full post method, it popoulated response with submitted data (where C is empty)
     
    public AAAResponse post(
         AAARequest REQUEST)
    {
        AAAResponse response = new AAAResponse();   
        List data = REQUEST.parmDATA();
        ListEnumerator enumerator = data.getEnumerator();
        str ret = '';
        while (enumerator.moveNext())
        {
            AAAData item = enumerator.current();
            
            ret += item.data(); //A + C (Extended)
        }
        response.VALUE(ret);
        return response;
    }
     
    as you can see only for demostration response contains the concatenation of A & C
    Method data() is extended in this way:
     
    public str data()
    {
        next data();
        return a + c;
    }
     
    This is the response:
     
    {
        "$id": "1",
        "VALUE": "123456"
    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 451 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 428 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans