This repository was archived by the owner on Jul 6, 2026. It is now read-only.
Emitter customization with field default value not reflected in fromJson method #3220
Copy link
Copy link
Closed
Closed
Copy link
Description
Description
I am renaming the variant of an enum and then adjusting the default value of a different class that uses this variant using the following customization code:
customization.getClass("com.azure.ai.agents.models", "ComputerActionType").customizeAst(ast -> ast.getEnumByName("ComputerActionType")
.ifPresent(clazz -> clazz.getEntries().stream()
.filter(entry -> "KEYPRESS".equals(entry.getName().getIdentifier()))
.forEach(entry -> entry.setName("KEY_PRESS"))));
customization.getClass("com.azure.ai.agents.models", "ComputerActionKeyPress")
.customizeAst(ast -> ast.getClassByName("ComputerActionKeyPress")
.flatMap(clazz -> clazz.getFieldByName("type"))
.ifPresent(barField ->
barField.getVariables().forEach(var -> {
if (var.getNameAsString().equals("type")) {
var.setInitializer("ComputerActionType.KEY_PRESS");
}
})));The generated code works almost as expected with the exception of how the deserialization method fromJson gets generated. I get the following:
@Immutable
public final class ComputerActionKeyPress extends ComputerAction {
/*
* The type property.
*/
@Generated
private ComputerActionType type = ComputerActionType.KEY_PRESS;
// ...
@Generated
public static ComputerActionKeyPress fromJson(JsonReader jsonReader) throws IOException {
return jsonReader.readObject(reader -> {
List<String> keys = null;
ComputerActionType type = ComputerActionType.KEYPRESS;
while (reader.nextToken() != JsonToken.END_OBJECT) {
String fieldName = reader.getFieldName();
reader.nextToken();
if ("keys".equals(fieldName)) {
keys = reader.readArray(reader1 -> reader1.getString());
// ....
// ...Expectation
The initialized value in the fromJson method also matches the new default value set in the customization.
Metadata
Metadata
Assignees
Labels
No labels
Activity
weidongxu-microsoft commentedon Nov 12, 2025
The
customizeAstis actually a pretty low level "modification" on the code (AST means Abstract Syntax Tree).Basically, this means you are directly changing the code (in this case, the initializer of
ComputerActionType.KEY_PRESS), and that code alone. Nothing would be changed anywhere else.So, if you use
customizeAst, you would need to modify thefromJsonas well.weidongxu-microsoft commentedon Nov 12, 2025
BTW, after we moved away from Eclipse language server, we now only have
customizeAst. Is it correct? Alan Zimmer (@alzimmermsft)alzimmermsft commentedon Nov 12, 2025
All of what Weidong Xu (@weidongxu-microsoft) said is correct.
Code customizations now only have a basic AST customization API which is on
ClassCustomizationand when using it if multiple spots in code use the modified code, field name change, method name change, etc, all usages will need to be modified manually. This was done as we should be preferring Swagger transforms and TypeSpec language customizations as those can be shared by all consumers of said Swagger and TypeSpec, whereas code customizations are specific to our code generation.jpalvarezl commentedon Nov 12, 2025
Thank you for the clarification.