pythonspyne

Remove tag from spyne response


I am using spyne to create a webservice, such that my code is like below:

class bndbox(ComplexModel):
    xmin = Integer
    ymin = Integer
    xmax = Integer  
    ymax = Integer
    score = Integer

class object(ComplexModel):
    name = String
    objects = Array(bndbox)
    
class SKUObjectsDetected(ComplexModel): 
    annotation = Array(object)


def add_SKUObject(skuobject):
    #global sku_object_database
    sku_object_database.append(skuobject)

class ObjectDetectionService(Service):
    @srpc(Unicode, _returns=SKUObjectsDetected)
    def find_objects(encoded_string):
        .
        .
        .
        return SKUObjectsDetected(annotation=sku_object_database)

It works properly. Actually the response is the following:

<soap11env:Envelope xmlns:tns="object_detection_service" xmlns:soap11env="http://schemas.xmlsoap.org/soap/envelope/">
  <soap11env:Body>
    <tns:find_objectsResponse>
      <tns:annotation>
        <tns:object>
          <tns:objects>
            <tns:bndbox>
              <tns:xmin>151</tns:xmin>
              <tns:ymin>183</tns:ymin>
              <tns:score>34</tns:score>
              <tns:xmax>169</tns:xmax>
              <tns:ymax>272</tns:ymax>
            </tns:bndbox>
            <tns:bndbox>
              <tns:xmin>190</tns:xmin>
              <tns:ymin>12</tns:ymin>
              <tns:score>32</tns:score>
              <tns:xmax>300</tns:xmax>
              <tns:ymax>92</tns:ymax>
            </tns:bndbox>
            <tns:bndbox>
              <tns:xmin>284</tns:xmin>
              <tns:ymin>5</tns:ymin>
              <tns:score>28</tns:score>
              <tns:xmax>300</tns:xmax>
              <tns:ymax>65</tns:ymax>
            </tns:bndbox>
          </tns:objects>
          <tns:name>Car</tns:name>
        </tns:object>        
      </tns:annotation>
    </tns:find_objectsResponse>
  </soap11env:Body>
</soap11env:Envelope>

But, is it possible to remove <tns:objects> tag? The other tags are well, I just need to remove this. It corresponds to objects array in object class.


Solution

  • instead of

    Array(bndbox)
    

    use

    bndbox.customize(max_occurs='unbounded')