Skip to content

Commit

Permalink
Added @JsonIgnore to prevent infinitive loops
Browse files Browse the repository at this point in the history
See also #174
  • Loading branch information
AB-xdev committed Jun 5, 2024
1 parent d45d8f8 commit 01b0adb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.4.2
* Added ``JsonIgnore`` to certain fields to help prevent infinite loops #174

## 1.4.1
* Use ``Number`` instead of ``BigDecimal`` in some additional places #159 (@aripddev)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.UncheckedIOException;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.core.JsonProcessingException;
Expand All @@ -34,7 +35,8 @@ public abstract class AbstractChart<T, O extends Options<?, ?>, D extends Abstra
protected D data;
protected O options;

protected final ObjectWriter objectWriter = new ObjectMapper()
@JsonIgnore
protected ObjectWriter defaultObjectWriter = new ObjectMapper()
.setDefaultPropertyInclusion(JsonInclude.Include.NON_EMPTY)
.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY)
.setVisibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.NONE)
Expand Down Expand Up @@ -84,12 +86,25 @@ public T setOptions(final O options)
return this.self();
}

@JsonIgnore
public ObjectWriter getDefaultObjectWriter()
{
return this.defaultObjectWriter;
}

@JsonIgnore
public T setDefaultObjectWriter(final ObjectWriter defaultObjectWriter)
{
this.defaultObjectWriter = defaultObjectWriter;
return this.self();
}

@Override
public String toJsonNative()
{
try
{
return this.objectWriter.writeValueAsString(this);
return this.defaultObjectWriter.writeValueAsString(this);
}
catch(final JsonProcessingException e)
{
Expand Down

0 comments on commit 01b0adb

Please sign in to comment.