@@ -45,7 +45,7 @@ public ToolInformation deserialize(JsonParser jsonParser, DeserializationContext
4545 return parseToolInformation (node );
4646 }
4747
48- private ToolInformation parseToolInformation (JsonNode toolsNode ) throws IOException {
48+ private ToolInformation parseToolInformation (JsonNode toolsNode ) {
4949 ToolInformation toolInformation = new ToolInformation ();
5050 if (toolsNode .has ("components" )) {
5151 parseComponents (toolsNode .get ("components" ), toolInformation );
@@ -58,24 +58,42 @@ private ToolInformation parseToolInformation(JsonNode toolsNode) throws IOExcept
5858
5959 private void parseComponents (JsonNode componentsNode , ToolInformation toolInformation ) {
6060 if (componentsNode != null ) {
61+ // Case JSON input where "components" is an array
6162 if (componentsNode .isArray ()) {
6263 List <Component > components = mapper .convertValue (componentsNode , new TypeReference <List <Component >>() {});
6364 toolInformation .setComponents (components );
64- } else if (componentsNode .isObject ()) {
65- Component component = mapper .convertValue (componentsNode , Component .class );
66- toolInformation .setComponents (Collections .singletonList (component ));
65+ }
66+ // Case XML-like input where "components" contains "component"
67+ else if (componentsNode .isObject () && componentsNode .has ("component" )) {
68+ JsonNode componentNode = componentsNode .get ("component" );
69+ if (componentNode .isArray ()) {
70+ List <Component > components = mapper .convertValue (componentNode , new TypeReference <List <Component >>() {});
71+ toolInformation .setComponents (components );
72+ } else if (componentNode .isObject ()) {
73+ Component component = mapper .convertValue (componentNode , Component .class );
74+ toolInformation .setComponents (Collections .singletonList (component ));
75+ }
6776 }
6877 }
6978 }
7079
7180 private void parseServices (JsonNode servicesNode , ToolInformation toolInformation ) {
7281 if (servicesNode != null ) {
82+ // Case JSON input where "services" is an array
7383 if (servicesNode .isArray ()) {
7484 List <Service > services = mapper .convertValue (servicesNode , new TypeReference <List <Service >>() {});
7585 toolInformation .setServices (services );
76- } else if (servicesNode .isObject ()) {
77- Service service = mapper .convertValue (servicesNode , Service .class );
78- toolInformation .setServices (Collections .singletonList (service ));
86+ }
87+ // Case XML-like input where "services" contains "component"
88+ else if (servicesNode .isObject () && servicesNode .has ("service" )) {
89+ JsonNode serviceNode = servicesNode .get ("service" );
90+ if (serviceNode .isArray ()) {
91+ List <Service > services = mapper .convertValue (servicesNode , new TypeReference <List <Service >>() {});
92+ toolInformation .setServices (services );
93+ } else if (serviceNode .isObject ()) {
94+ Service service = mapper .convertValue (servicesNode , Service .class );
95+ toolInformation .setServices (Collections .singletonList (service ));
96+ }
7997 }
8098 }
8199 }
0 commit comments