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

Transient are ignored in response #2316

Closed
lowcasz opened this issue Oct 11, 2023 · 1 comment
Closed

Transient are ignored in response #2316

lowcasz opened this issue Oct 11, 2023 · 1 comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply

Comments

@lowcasz
Copy link

lowcasz commented Oct 11, 2023

I have some fields which should be displayed in response, but not stored in db.
I'm trying to add property to response, but I can't.
Using additional getters, it doesn't work.
Using @transient fields with @PolstLoad calculate() method, it doesn't work too?

IMO Response should be controlled by @JsonIgnore/@JsonInclude instead of @transient
Is it purposeful behaviour?
Can I do this on Entity level without overrides/create controller?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 11, 2023
@mp911de mp911de added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged labels Oct 16, 2023
@mp911de
Copy link
Member

mp911de commented Oct 17, 2023

We do not filter transient properties from the Jackson representation.

"_embedded": {
"persons": [
{
  "name": "John",
  "greeting": "Hello John",
  "_links": {
    "self": {
      "href": "http://localhost:8080/persons/1"
    },
    "person": {
      "href": "http://localhost:8080/persons/1"
    }
  }
},…
@Entity
public class Person {

	@Id @GeneratedValue Long id;
	String name;
	@Transient String greeting;


	public Person() {
	}

	public Person(Long id, String name) {
		this.id = id;
		this.name = name;
		this.greeting = "Hello " + name;
	}

	@PostLoad
	public void postLoad() {
		this.greeting = "Hello " + name;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getGreeting() {
		return greeting;
	}

	public void setGreeting(String greeting) {
		this.greeting = greeting;
	}

}

Please note that there is also an association for certain operations (such as PATCH) that require a property mapping between its persistent state and its REST representation.

@mp911de mp911de closed this as not planned Won't fix, can't repro, duplicate, stale Oct 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

3 participants