Skip to content
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

[Java] Codegen Bad object serialization when query parameter is Object #907

Open
SebastienRvl opened this issue Aug 27, 2018 · 11 comments
Open

Comments

@SebastienRvl
Copy link

SebastienRvl commented Aug 27, 2018

Description

When y try to send an object in a query with method get, the object is not serialized, the api call toString method

14:57:56.747 [main] DEBUG f.r.p.t.f.l.j.s.r.RestLoggerProvider - --> GET http://localhost:8000/v1/declarations/etablissements?page=class%20PageIn%20%7B%0A%20%20%20%20page%3A%200%0A%20%20%20%20size%3A%200%0A%7D&filtre=class%20FiltreRechercherEtablissementDSN%20%7B%0A%20%20%20%20siret%3A%20null%0A%20%20%20%20siren%3A%20502195977%0A%20%20%20%20annee%3A%20null%0A%20%20%20%20mois%3A%20null%0A%20%20%20%20localite%3A%20null%0A%20%20%20%20effectifCalculeDebutDePeriode%3A%20null%0A%20%20%20%20effectifCalculeFinDePeriode%3A%20null%0A%20%20%20%20denomination%3A%20null%0A%20%20%20%20codeNAF%3A%20null%0A%7D&tri=class%20TriRechercherEtablissementsDSN%20%7B%0A%20%20%20%20siret%3A%20null%0A%20%20%20%20siren%3A%20null%0A%20%20%20%20mois%3A%20null%0A%20%20%20%20localite%3A%20null%0A%20%20%20%20effectifCalculeFinDePeriode%3A%20null%0A%20%20%20%20effectifCalculeDebutDePeriode%3A%20null%0A%20%20%20%20denomination%3A%20null%0A%20%20%20%20codeNAF%3A%20null%0A%20%20%20%20annee%3A%20asc%0A%7D HTTP/1.1

openapi-generator version

3.2.1, 3.2.2 ...

OpenAPI declaration file content or url
'/declarations/etablissements':
    get:
      summary: 'Ce service permet de rechercher les établissements rattachés à une entreprise dans la base stockant les Déclarations Sociales Nominatives à partir d’un Siren et d’une période de déclaration mensuelle.'
      description: |
...
      tags:
        - declarations
        - v1.4.0
      operationId: rechercherDeclarationsEtablissementsDSN
      parameters:
        - name: page
          in: query
          required: false
          style: form
          schema:
            $ref: '#/components/schemas/PageIn'
        - name: filtre
          in: query
          required: false
          style: form
          schema:
            $ref: '#/components/schemas/FiltreRechercherEtablissementDSN'
          example:
            siret: "94555054900162"
        - name: tri
          in: query
          required: false
          style: form
          explode: false
          schema:
            $ref: '#/components/schemas/TriRechercherEtablissementsDSN'
          example:
            denomination: asc
      responses:
        '200':
          description: "Liste d'établissements"
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReponseRechercherEtablissement'
        500:
          $ref: '#/components/responses/Erreur_Response'
Command line used for generation
					<execution>
						<id>generate-client-1.2.0</id>
						<goals>
							<goal>generate</goal>
						</goals>
						<phase>generate-sources</phase>
						<configuration>
							<inputSpec>${project.basedir}/src/main/resources/dsnci_ws_consultation_be_v1.2.0.yaml</inputSpec>
							<language>java</language>
							<apiPackage>fr.recouv.dsn.ws.rest.api.v1_0</apiPackage>
							<modelPackage>fr.recouv.dsn.ws.rest.dto.v1_0</modelPackage>
							<output>${generated-swagger-path}</output>
							<withXml>true</withXml>
							<generateApis>true</generateApis>
							<generateApiTests>true</generateApiTests>
						</configuration>
					</execution>
Steps to reproduce
Related issues/PRs
Suggest a fix/enhancement
@SebastienRvl SebastienRvl changed the title Bad object serialization when query parameter is Object [Java] Bad object serialization when query parameter is Object Aug 27, 2018
@SebastienRvl SebastienRvl changed the title [Java] Bad object serialization when query parameter is Object [Java] Codegen Bad object serialization when query parameter is Object Aug 27, 2018
@sorin-florea
Copy link
Contributor

I created a PR to fix this.

@sorin-florea
Copy link
Contributor

This issue will be fixed by #12369

@moravcik94
Copy link

issue still here with 6.2.1 release

@sorin-florea
Copy link
Contributor

@moravcik94 please share a reproducer schema and which generator you are using.

@moravcik94
Copy link

moravcik94 commented Nov 28, 2022

@moravcik94 please share a reproducer schema and which generator you are using.

@sorin-florea
Generator: java, Library: resttemplate
schema:

/users/list:
   get:
     tags:
       - users-controller
     operationId: listUsers
     parameters:
       - name: filter
         in: query
         required: true
         schema:
           $ref: '#/components/schemas/UsersFilter'

ends up with call:
http://xyz.com/api/v1/users/list?filter=class%20UsersFilter%20%7B%0A%20%20%20%20firstResult:%20null%0A%20%20%20%20maxResults:%20null%0A%20%20%20%20orderBy:%20null%0A%20%20%20%20ascending:%20null%0A%20%20%20%20displayRecords:%20null%0A%20%20%20%20isOvmMetaIsCode:%20null%0A%20%20%20%20name:%20Finan%C4%8Dn%C3%A1%20spr%C3%A1va%20-%20nedoplatky%0A%20%20%20%20useCase:%20null%0A%20%20%20%20ovmIds:%20null%0A%7D

@sorin-florea
Copy link
Contributor

@moravcik94 resttemplate library is not fixed. Only native and apache-http.

@moravcik94
Copy link

@sorin-florea is there any workaround how to use it with resttemplate ?

@sorin-florea
Copy link
Contributor

sorin-florea commented Dec 5, 2022

@moravcik94 The only workaround would be to not use a ref for now. You can also try to fix the issue for resttemplate.

@GregDThomas
Copy link
Contributor

I'm working on a PR now to fix this - #14825 - the updated template works, just need to get the whitespace issues sorted nicely, but unfortunately have had to be pulled out on to other things.

@GregDThomas
Copy link
Contributor

PR is ready to go - with it java-resttemplate correctly explodes query parameters.

@GregDThomas
Copy link
Contributor

The bad news is, now I've got the client code working correctly, I've uncovered an issue with the spring-boot library on the server side. No idea where to begin on that one though. #14860

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants