Skip to content

Passing tests for #2135 #5083

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.fasterxml.jackson.databind.deser.creators;

import java.util.*;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.*;

import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil;

import static org.junit.jupiter.api.Assertions.*;

public class Creator2135Test extends DatabindTestUtil
{
static class House {
@JsonProperty(required = true)
List<Brick> bricks = new ArrayList<>();

@JsonProperty(required = true)
Integer houseNumber;

@JsonCreator
public House(@JsonProperty(value = "bricks", required = true) List<Brick> bricks,
@JsonProperty(value = "houseNumber", required = true) Integer houseNumber) {
this.bricks.addAll(bricks);
this.houseNumber = houseNumber;
}

public List<Brick> getBricks() {
return bricks;
}

public Integer getHouseNumber() {
return houseNumber;
}
}

static class Brick {
@JsonProperty(required = true)
final String code;

boolean creatorCalled;

public Brick(@JsonProperty("code") String code) {
this.code = code;
creatorCalled = true;
}

@JsonCreator
static Brick create(String code) {
return new Brick(code);
}

}

private final ObjectMapper MAPPER = newJsonMapper();

@Test
void testBricksFromObject() throws Exception {
House house = MAPPER.readValue(
"{ \"bricks\": [{ \"code\": \"aa\" }, { \"code\": \"abcd\" } ], \"houseNumber\": 99 }", House.class);
assertNotNull(house);
assertEquals(2, house.getBricks().size());
assertTrue(house.bricks.get(0).creatorCalled);
assertTrue(house.bricks.get(1).creatorCalled);
}

@Test
void testBricksFromStrings() throws Exception {
House house = MAPPER.readValue(
"{ \"bricks\": [\"aa\", \"abcd\"], \"houseNumber\": 99 }", House.class);
assertNotNull(house);
assertEquals(2, house.getBricks().size());
assertTrue(house.bricks.get(0).creatorCalled);
assertTrue(house.bricks.get(1).creatorCalled);
}
}