-
Notifications
You must be signed in to change notification settings - Fork 293
http-client-java, xml support in core-v2 #7788
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
Merged
weidongxu-microsoft
merged 23 commits into
microsoft:main
from
weidongxu-microsoft:http-client-java_xml
Jul 10, 2025
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
67559f9
include xml test
weidongxu-microsoft 49e5964
init xml support
weidongxu-microsoft 4ee7dc6
regen
weidongxu-microsoft 1c140a0
fix update on final List
weidongxu-microsoft 2f9200c
regen clientcore
weidongxu-microsoft 4597b0a
test
weidongxu-microsoft 85727aa
fix required unwrapped array
weidongxu-microsoft 2ae3133
fix
weidongxu-microsoft 62dad43
test
weidongxu-microsoft a56470a
add xml.ts in local, to fix a spelling problem in codemodel
weidongxu-microsoft 84e3aa0
Merge branch 'main' into http-client-java_xml
weidongxu-microsoft 08dc863
code comments
weidongxu-microsoft e8c21eb
test
weidongxu-microsoft 095805a
fix required list in unwrapped
weidongxu-microsoft 7a61ecf
regen
weidongxu-microsoft d14316e
disable GET test
weidongxu-microsoft ee79588
comment
weidongxu-microsoft 196801d
improve logic on getter of null list
weidongxu-microsoft e7ce470
Merge branch 'main' into http-client-java_xml
weidongxu-microsoft 37391e6
restrict the logic to azure v1
weidongxu-microsoft 2c8b3a6
Merge branch 'main' into http-client-java_xml
weidongxu-microsoft 0ce28fa
regen after refresh main
weidongxu-microsoft 7a6f70a
rename var
weidongxu-microsoft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
packages/http-client-java/emitter/src/common/formats/xml.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { SerializationFormat } from "@autorest/codemodel"; | ||
|
||
export interface XmlSerializationFormat extends SerializationFormat { | ||
name?: string; | ||
namespace?: string; | ||
prefix?: string; | ||
attribute: boolean; | ||
wrapped: boolean; | ||
text: boolean; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
...ttp-client-generator-clientcore-test/src/main/java/payload/xml/ModelWithArrayOfModel.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package payload.xml; | ||
|
||
import io.clientcore.core.annotations.Metadata; | ||
import io.clientcore.core.annotations.MetadataProperties; | ||
import io.clientcore.core.serialization.xml.XmlReader; | ||
import io.clientcore.core.serialization.xml.XmlSerializable; | ||
import io.clientcore.core.serialization.xml.XmlToken; | ||
import io.clientcore.core.serialization.xml.XmlWriter; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import javax.xml.namespace.QName; | ||
import javax.xml.stream.XMLStreamException; | ||
|
||
/** | ||
* Contains an array of models. | ||
*/ | ||
@Metadata(properties = { MetadataProperties.IMMUTABLE }) | ||
public final class ModelWithArrayOfModel implements XmlSerializable<ModelWithArrayOfModel> { | ||
/* | ||
* The items property. | ||
*/ | ||
@Metadata(properties = { MetadataProperties.GENERATED }) | ||
private final List<SimpleModel> items; | ||
|
||
/** | ||
* Creates an instance of ModelWithArrayOfModel class. | ||
* | ||
* @param items the items value to set. | ||
*/ | ||
@Metadata(properties = { MetadataProperties.GENERATED }) | ||
public ModelWithArrayOfModel(List<SimpleModel> items) { | ||
this.items = items; | ||
} | ||
|
||
/** | ||
* Get the items property: The items property. | ||
* | ||
* @return the items value. | ||
*/ | ||
@Metadata(properties = { MetadataProperties.GENERATED }) | ||
public List<SimpleModel> getItems() { | ||
return this.items; | ||
} | ||
|
||
@Metadata(properties = { MetadataProperties.GENERATED }) | ||
@Override | ||
public XmlWriter toXml(XmlWriter xmlWriter) throws XMLStreamException { | ||
return toXml(xmlWriter, null); | ||
} | ||
|
||
@Metadata(properties = { MetadataProperties.GENERATED }) | ||
@Override | ||
public XmlWriter toXml(XmlWriter xmlWriter, String rootElementName) throws XMLStreamException { | ||
rootElementName | ||
= rootElementName == null || rootElementName.isEmpty() ? "ModelWithArrayOfModel" : rootElementName; | ||
xmlWriter.writeStartElement(rootElementName); | ||
if (this.items != null) { | ||
xmlWriter.writeStartElement("items"); | ||
for (SimpleModel element : this.items) { | ||
xmlWriter.writeXml(element, "SimpleModel"); | ||
} | ||
xmlWriter.writeEndElement(); | ||
} | ||
return xmlWriter.writeEndElement(); | ||
} | ||
|
||
/** | ||
* Reads an instance of ModelWithArrayOfModel from the XmlReader. | ||
* | ||
* @param xmlReader The XmlReader being read. | ||
* @return An instance of ModelWithArrayOfModel if the XmlReader was pointing to an instance of it, or null if it | ||
* was pointing to XML null. | ||
* @throws IllegalStateException If the deserialized XML object was missing any required properties. | ||
* @throws XMLStreamException If an error occurs while reading the ModelWithArrayOfModel. | ||
*/ | ||
@Metadata(properties = { MetadataProperties.GENERATED }) | ||
public static ModelWithArrayOfModel fromXml(XmlReader xmlReader) throws XMLStreamException { | ||
return fromXml(xmlReader, null); | ||
} | ||
|
||
/** | ||
* Reads an instance of ModelWithArrayOfModel from the XmlReader. | ||
* | ||
* @param xmlReader The XmlReader being read. | ||
* @param rootElementName Optional root element name to override the default defined by the model. Used to support | ||
* cases where the model can deserialize from different root element names. | ||
* @return An instance of ModelWithArrayOfModel if the XmlReader was pointing to an instance of it, or null if it | ||
* was pointing to XML null. | ||
* @throws IllegalStateException If the deserialized XML object was missing any required properties. | ||
* @throws XMLStreamException If an error occurs while reading the ModelWithArrayOfModel. | ||
*/ | ||
@Metadata(properties = { MetadataProperties.GENERATED }) | ||
public static ModelWithArrayOfModel fromXml(XmlReader xmlReader, String rootElementName) throws XMLStreamException { | ||
String finalRootElementName | ||
= rootElementName == null || rootElementName.isEmpty() ? "ModelWithArrayOfModel" : rootElementName; | ||
return xmlReader.readObject(finalRootElementName, reader -> { | ||
List<SimpleModel> items = null; | ||
while (reader.nextElement() != XmlToken.END_ELEMENT) { | ||
QName elementName = reader.getElementName(); | ||
|
||
if ("items".equals(elementName.getLocalPart())) { | ||
while (reader.nextElement() != XmlToken.END_ELEMENT) { | ||
elementName = reader.getElementName(); | ||
if ("SimpleModel".equals(elementName.getLocalPart())) { | ||
if (items == null) { | ||
items = new ArrayList<>(); | ||
} | ||
items.add(SimpleModel.fromXml(reader, "SimpleModel")); | ||
} else { | ||
reader.skipElement(); | ||
} | ||
} | ||
} else { | ||
reader.skipElement(); | ||
} | ||
} | ||
return new ModelWithArrayOfModel(items); | ||
}); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.