Rails 5.2.8: how to remove nil=true when rendering null values in xml response

31 views Asked by At

I am using rails 5.2.8 version and usinggem 'activemodel-serializers-xml' and acts_as_api for rendering xml response.

below code is rendering xml response.

@student = Student.first
format.xml  { render_for_api :response, xml:  @student, skip_types: true }

Below is the response body

<?xml version="1.0" encoding="UTF-8"?>
<student>
<name nil="true"/>
<lastname nil="true"/>
</student>

I have upgraded rails gem from 3 to 5.2.8 version. old response body for same code before upgrading rails version is shown below.

<?xml version="1.0" encoding="UTF-8"?>
<student>
<name</name>
<lastname></lastname>
</student>

As you can see in rails upgraded version attributes are rendered with nil=true and in old rails it is rendered as <name empty tag. I want to retain old behaviour in rails 5.2.8 version. what is the option i can provide to format.xml method so that response body will reamin same in rails 5.2.8 version ?

0

There are 0 answers