Giter Club home page Giter Club logo

Comments (17)

RomanKurbanov avatar RomanKurbanov commented on May 24, 2024

Okay, i narrowed it down a bit:
if we have a DataTable sending DataTableInput through POST-reqeust - DataTablesRepository outputs fields seemingly at random. But if it uses GET-request - JsonView annotation works all of the sudden.

Tested it on a second project - same behaviour.
Changed issue name.

from spring-data-jpa-datatables.

sebasira avatar sebasira commented on May 24, 2024

I'm having the same issue as you (earlier) do. I can not hide properties with @JSONVIEW not even with @JsonIgnore. I'm using v4.3

from spring-data-jpa-datatables.

sebasira avatar sebasira commented on May 24, 2024

Well... it's strange.... now it's working with both GET and POST. I've switch back and forth from one method to another and they started to work (using @JSONVIEW).

from spring-data-jpa-datatables.

RomanKurbanov avatar RomanKurbanov commented on May 24, 2024

@sebasira In my case it very consistently doesn't work.

from spring-data-jpa-datatables.

sebasira avatar sebasira commented on May 24, 2024

@iSosnitsky give a few days and I'll put my code here

from spring-data-jpa-datatables.

RomanKurbanov avatar RomanKurbanov commented on May 24, 2024

Now things get kinda odd.
It totally works if i use findAll(); with an empty DataTablesInput, like that:

@JsonView(DataTablesOutput.View.class)
    @RequestMapping(value = "/users", method = RequestMethod.GET)
    public DataTablesOutput<User> getUsers() {
        return userRepository.findAll(new DataTablesInput());
    }

But if i use DataTables provided input, it stops working:

@JsonView(DataTablesOutput.View.class)
    @RequestMapping(value = "/users", method = RequestMethod.GET)
    public DataTablesOutput<User> getUsers(@Valid DataTablesInput input) {
        return userRepository.findAll(input);
    }

Now i suspect DataTables itself.

i'm using DataTables 1.10.16

Update:
It only worked when i opened it in my browser and saw data from controller from there, which was XML.
But when i use Postman for example, it doesn't work.

If i explicitly declare that this method produces JSON, then it won't work in any way no matter how you bend it:

@JsonView(DataTablesOutput.View.class)
    @RequestMapping(value = "/users", method = RequestMethod.GET, produces = "application/json; charset=UTF-8")
    public DataTablesOutput<User> getUsers() {
        return userRepository.findAll(new DataTablesInput());
    }

Mapping to XML as i remember, was used in previous versions.
Therefore, i assume that json mapper is not even using this feature.

from spring-data-jpa-datatables.

darrachequesne avatar darrachequesne commented on May 24, 2024

Hi, I'm not able to reproduce with GET or POST requests: https://github.com/darrachequesne/spring-data-jpa-datatables-sample/tree/issue-79

In both cases, only id, firstName and lastName are displayed.

from spring-data-jpa-datatables.

RomanKurbanov avatar RomanKurbanov commented on May 24, 2024

@darrachequesne Hi, thanks a lot for answering.
I downloaded the branch and now am trying to reproduce the issue.
The sample you provided works flawlessly, by the way.

from spring-data-jpa-datatables.

RomanKurbanov avatar RomanKurbanov commented on May 24, 2024

@darrachequesne Yeah, i reproduced it.
The issue was in WebConfig - i used Jackson-datatype-hibernate5 as a MessageConverter in my WebConfig.
Where can i show you modified sample project?

from spring-data-jpa-datatables.

darrachequesne avatar darrachequesne commented on May 24, 2024

Great! Could you please fork the repository, and push the branch with the failure on it?

from spring-data-jpa-datatables.

RomanKurbanov avatar RomanKurbanov commented on May 24, 2024

@darrachequesne https://github.com/iSosnitsky/spring-data-jpa-datatables-sample

from spring-data-jpa-datatables.

darrachequesne avatar darrachequesne commented on May 24, 2024

@iSosnitsky thanks for providing a way to reproduce! It seems you have to manually disable the DEFAULT_VIEW_INCLUSION (it is disabled by default in Spring Boot, but was enabled in your case):

class HibernateAwareObjectMapper extends ObjectMapper {
    public HibernateAwareObjectMapper() {
        Hibernate5Module module = new Hibernate5Module();
        module.disable(Hibernate5Module.Feature.USE_TRANSIENT_ANNOTATION);
        this.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
        this.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
+       this.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false);
        this.registerModule(module);
    }
}

from spring-data-jpa-datatables.

RomanKurbanov avatar RomanKurbanov commented on May 24, 2024

@darrachequesne Thanks, it works!
Mind if i put that in your project's Wiki?

from spring-data-jpa-datatables.

RomanKurbanov avatar RomanKurbanov commented on May 24, 2024

By the way, if you declare a lazy loaded field as a non-searchable, it won't be initialized:

{
                    data: 'office.city',
                    render: function (data) { return data ? data : '-'; },
                    searchable: false
                }

from spring-data-jpa-datatables.

darrachequesne avatar darrachequesne commented on May 24, 2024

@iSosnitsky let's add that to the README, if you will.

Regarding the lazy-loaded field, it seems you are right! Would you mind opening a new issue for that?

from spring-data-jpa-datatables.

RomanKurbanov avatar RomanKurbanov commented on May 24, 2024

@darrachequesne Sure!

from spring-data-jpa-datatables.

darrachequesne avatar darrachequesne commented on May 24, 2024

Closed due to inactivity, please reopen if needed.

from spring-data-jpa-datatables.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.