diff --git a/tests/fixtures/defxmlschema/chapter01.json b/tests/fixtures/defxmlschema/chapter01.json index c473043c4..b1de8fdf3 100644 --- a/tests/fixtures/defxmlschema/chapter01.json +++ b/tests/fixtures/defxmlschema/chapter01.json @@ -1,5 +1,5 @@ { "number": 557, "size": 10, - "eff_date": "2001-04-02" + "effDate": "2001-04-02" } \ No newline at end of file diff --git a/tests/fixtures/defxmlschema/chapter08.json b/tests/fixtures/defxmlschema/chapter08.json index 6423acf10..94f1b61e7 100644 --- a/tests/fixtures/defxmlschema/chapter08.json +++ b/tests/fixtures/defxmlschema/chapter08.json @@ -1,17 +1,17 @@ { - "dress_size": [ + "dressSize": [ "06" ], - "medium_dress_size": [ + "mediumDressSize": [ "12" ], - "small_dress_size": [ + "smallDressSize": [ "6" ], - "smlx_size": [ + "smlxSize": [ "extra large" ], - "xsmlx_size": [ + "xsmlxSize": [ "extra small" ] } \ No newline at end of file diff --git a/tests/fixtures/defxmlschema/chapter10.json b/tests/fixtures/defxmlschema/chapter10.json index 3dfd5b669..81a7f06ac 100644 --- a/tests/fixtures/defxmlschema/chapter10.json +++ b/tests/fixtures/defxmlschema/chapter10.json @@ -3,23 +3,23 @@ 12, "medium" ], - "small_size": [ + "smallSize": [ "6", "small" ], - "international_size": [ + "internationalSize": [ 12, 24, "large" ], - "available_sizes": [ + "availableSizes": [ [ 10, "large", 2 ] ], - "applicable_sizes": [ + "applicableSizes": [ "small medium large" ] } \ No newline at end of file diff --git a/tests/fixtures/defxmlschema/chapter12.json b/tests/fixtures/defxmlschema/chapter12.json index 2794cceb7..357f1313c 100644 --- a/tests/fixtures/defxmlschema/chapter12.json +++ b/tests/fixtures/defxmlschema/chapter12.json @@ -31,7 +31,7 @@ ] } ], - "eff_date": "2002-04-02", + "effDate": "2002-04-02", "other_attributes": {} }, { @@ -44,7 +44,7 @@ "value": "red" } ], - "eff_date": "1900-01-01", + "effDate": "1900-01-01", "other_attributes": { "{http://example.org/oth}custom": "12" } diff --git a/tests/fixtures/defxmlschema/chapter13.json b/tests/fixtures/defxmlschema/chapter13.json index 81b299dea..5ff8c5dc0 100644 --- a/tests/fixtures/defxmlschema/chapter13.json +++ b/tests/fixtures/defxmlschema/chapter13.json @@ -1,11 +1,11 @@ { "hat": [ { - "routing_num": 123456, + "routingNum": 123456, "number": 557, "name": "Ten-Gallon Hat", "description": "This is a great hat!", - "eff_date": "2002-04-02", + "effDate": "2002-04-02", "lang": "en-US" } ], @@ -14,9 +14,9 @@ "number": 557, "name": "Ten-Gallon Hat", "description": null, - "routing_num": 123, + "routingNum": 123, "lang": null, - "eff_date": "2002-04-02" + "effDate": "2002-04-02" } ], "shirt": [ @@ -24,9 +24,9 @@ "number": 557, "name": "Short-Sleeved Linen Blouse", "description": null, - "routing_num": 124, + "routingNum": 124, "lang": null, - "eff_date": "2002-04-02", + "effDate": "2002-04-02", "size": [ { "value": 6, diff --git a/tests/fixtures/defxmlschema/chapter15.json b/tests/fixtures/defxmlschema/chapter15.json index fdd23d1c5..ee7db0524 100644 --- a/tests/fixtures/defxmlschema/chapter15.json +++ b/tests/fixtures/defxmlschema/chapter15.json @@ -9,5 +9,5 @@ }, "id": "P557", "version": "100", - "eff_date": null + "effDate": null } \ No newline at end of file diff --git a/tests/fixtures/primer/order.json b/tests/fixtures/primer/order.json index 5174a1d39..777bb2105 100644 --- a/tests/fixtures/primer/order.json +++ b/tests/fixtures/primer/order.json @@ -1,5 +1,5 @@ { - "ship_to": { + "shipTo": { "name": "Alice Smith", "street": "123 Maple Street", "city": "Mill Valley", @@ -7,7 +7,7 @@ "zip": "90952", "country": "US" }, - "bill_to": { + "billTo": { "name": "Robert Smith", "street": "8 Oak Avenue", "city": "Old Town", @@ -19,22 +19,22 @@ "items": { "item": [ { - "product_name": "Lawnmower", + "productName": "Lawnmower", "quantity": 1, - "usprice": "148.95", + "USPrice": "148.95", "comment": "Confirm this is electric", - "ship_date": null, - "part_num": "872-AA" + "shipDate": null, + "partNum": "872-AA" }, { - "product_name": "Baby Monitor", + "productName": "Baby Monitor", "quantity": 1, - "usprice": "39.98", + "USPrice": "39.98", "comment": null, - "ship_date": "1999-05-21", - "part_num": "926-AA" + "shipDate": "1999-05-21", + "partNum": "926-AA" } ] }, - "order_date": "1999-10-20" + "orderDate": "1999-10-20" } \ No newline at end of file diff --git a/tests/formats/dataclass/test_client.py b/tests/formats/dataclass/test_client.py index b670d3276..cbcb86ffb 100644 --- a/tests/formats/dataclass/test_client.py +++ b/tests/formats/dataclass/test_client.py @@ -48,7 +48,7 @@ def test_send_with_dict_params(self, mock_post): mock_post.return_value = response.encode() client = Client.from_service(CalculatorSoapAdd) - params = {"body": {"add": {"int_a": 3, "int_b": 4}}} + params = {"Body": {"Add": {"intA": 3, "intB": 4}}} result = client.send(params, headers={"User-Agent": "xsdata"}) diff --git a/tests/formats/dataclass/test_elements.py b/tests/formats/dataclass/test_elements.py index dc2ddbcd6..a16ea3ee8 100644 --- a/tests/formats/dataclass/test_elements.py +++ b/tests/formats/dataclass/test_elements.py @@ -79,6 +79,10 @@ def test_init_with_xml_type(self): self.assertEqual("Unknown xml type `xsdata`", str(cm.exception)) + def test_property_lname(self): + var = XmlVar(name="a", qname="{B}A") + self.assertEqual("A", var.lname) + def test_property_clazz(self): var = XmlVar(name="foo", qname="foo") self.assertIsNone(var.clazz) diff --git a/tests/integration/test_calculator.py b/tests/integration/test_calculator.py index 256582035..a8ec88d61 100644 --- a/tests/integration/test_calculator.py +++ b/tests/integration/test_calculator.py @@ -43,7 +43,7 @@ def test_client(self, mock_most): config = Config.from_service(CalculatorSoapAdd) serializer = XmlSerializer(config=SerializerConfig(pretty_print=True)) client = Client(config=config, serializer=serializer) - result = client.send({"body": {"add": {"int_a": 1, "int_b": 3}}}) + result = client.send({"Body": {"Add": {"intA": 1, "intB": 3}}}) self.assertIsInstance(result, CalculatorSoapAddOutput) diff --git a/tests/integration/test_hello_rpc.py b/tests/integration/test_hello_rpc.py index 131d809da..fd5f444d0 100644 --- a/tests/integration/test_hello_rpc.py +++ b/tests/integration/test_hello_rpc.py @@ -46,7 +46,7 @@ def test_client(self, mock_most): config = Config.from_service(HelloGetHelloAsString) serializer = XmlSerializer(config=SerializerConfig(pretty_print=True)) client = Client(config=config, serializer=serializer) - result = client.send({"body": {"get_hello_as_string": {"arg0": "chris"}}}) + result = client.send({"Body": {"getHelloAsString": {"arg0": "chris"}}}) self.assertIsInstance(result, HelloGetHelloAsString.output) @@ -70,7 +70,7 @@ def test_client_with_soap_fault(self, mock_most): config = Config.from_service(HelloGetHelloAsString) serializer = XmlSerializer(config=SerializerConfig(pretty_print=True)) client = Client(config=config, serializer=serializer) - result = client.send({"body": {"get_hello_as_string": {"arg0": "chris"}}}) + result = client.send({"Body": {"getHelloAsString": {"arg0": "chris"}}}) self.assertIsInstance(result, HelloGetHelloAsString.output) @@ -90,5 +90,5 @@ def test_live(self): config = Config.from_service(HelloGetHelloAsString) serializer = XmlSerializer(config=SerializerConfig(pretty_print=True)) client = Client(config=config, serializer=serializer) - result = client.send({"body": {"get_hello_as_string": {"arg0": "chris"}}}) + result = client.send({"Body": {"getHelloAsString": {"arg0": "chris"}}}) print(result) diff --git a/xsdata/formats/dataclass/models/elements.py b/xsdata/formats/dataclass/models/elements.py index 1b08c8003..c0b233c97 100644 --- a/xsdata/formats/dataclass/models/elements.py +++ b/xsdata/formats/dataclass/models/elements.py @@ -90,6 +90,12 @@ def __post_init__(self, xml_type: Optional[str]): elif xml_type: raise XmlContextError(f"Unknown xml type `{xml_type}`") + @property + def lname(self) -> str: + """Local name.""" + _, name = split_qname(self.qname) + return name + @property def clazz(self) -> Optional[Type]: """Return the first type if field is bound to a dataclass.""" diff --git a/xsdata/formats/dataclass/parsers/json.py b/xsdata/formats/dataclass/parsers/json.py index e71b79abc..084f22beb 100644 --- a/xsdata/formats/dataclass/parsers/json.py +++ b/xsdata/formats/dataclass/parsers/json.py @@ -4,7 +4,6 @@ import warnings from dataclasses import dataclass from dataclasses import field -from dataclasses import fields from dataclasses import is_dataclass from typing import Any from typing import Dict @@ -79,7 +78,7 @@ def bind_dataclass(self, data: Dict, clazz: Type[T]) -> T: """Recursively build the given model from the input dict data.""" params = {} for var in self.context.build(clazz).vars: - value = data.get(var.name) + value = data.get(var.lname) if value is None or not var.init: continue @@ -181,7 +180,8 @@ def bind_choice_dataclass(self, value: Dict, var: XmlVar) -> Any: keys = set(value.keys()) for choice in var.choices: if choice.clazz: - attrs = {f.name for f in fields(choice.clazz)} + meta = self.context.build(choice.clazz) + attrs = {var.lname for var in meta.vars} if attrs == keys: return self.bind_value(choice, value) diff --git a/xsdata/formats/dataclass/serializers/json.py b/xsdata/formats/dataclass/serializers/json.py index 9a4d407ae..2ab14b149 100644 --- a/xsdata/formats/dataclass/serializers/json.py +++ b/xsdata/formats/dataclass/serializers/json.py @@ -64,7 +64,7 @@ def convert(self, obj: Any, var: Optional[XmlVar] = None) -> Any: if var is None or is_dataclass(obj): return self.dict_factory( [ - (var.name, self.convert(getattr(obj, var.name), var)) + (var.lname, self.convert(getattr(obj, var.name), var)) for var in self.context.build(obj.__class__).vars ] )