### Question:
JsonFieldWriter implements AtlasFieldWriter { @Override public void write(AtlasInternalSession session) throws AtlasException { Field targetField = session.head().getTargetField(); if (targetField == null) { throw new AtlasException(new IllegalArgumentException("Argument 'jsonField' cannot be null")); } if (LOG.isDebugEnabled()) { LOG.debug("Field: " + AtlasModelFactory.toString(targetField)); LOG.debug("Field type=" + targetField.getFieldType() + " path=" + targetField.getPath() + " v=" + targetField.getValue()); } AtlasPath path = new AtlasPath(targetField.getPath()); SegmentContext lastSegment = path.getLastSegment(); if (this.rootNode == null) { if (path.hasCollectionRoot()) { this.rootNode = objectMapper.createArrayNode(); } else { this.rootNode = objectMapper.createObjectNode(); } } ContainerNode<?> parentNode = this.rootNode; SegmentContext parentSegment = null; for (SegmentContext segment : path.getSegments(true)) { if (!segment.equals(lastSegment)) { if (LOG.isDebugEnabled()) { LOG.debug("Now processing parent segment: " + segment); } JsonNode childNode; if (segment.isRoot()) { if (parentNode instanceof ArrayNode) { childNode = parentNode; } else { parentSegment = segment; continue; } } else { childNode = getChildNode(parentNode, parentSegment, segment); } if (childNode == null) { childNode = createParentNode(parentNode, parentSegment, segment); } else if (childNode instanceof ArrayNode) { Integer index = segment.getCollectionIndex(); if (index == null) { return; } ArrayNode arrayChild = (ArrayNode) childNode; if (arrayChild.size() < (index + 1)) { if (LOG.isDebugEnabled()) { LOG.debug("Object Array is too small, resizing to accomodate index: " + index + ", current array: " + arrayChild); } while (arrayChild.size() < (index + 1)) { arrayChild.addObject(); } if (LOG.isDebugEnabled()) { LOG.debug("Object Array after resizing: " + arrayChild); } } childNode = arrayChild.get(index); } if (childNode == null) { return; } parentNode = (ObjectNode) childNode; parentSegment = segment; } else { if (targetField.getFieldType() == FieldType.COMPLEX) { createParentNode(parentNode, parentSegment, segment); return; } if (LOG.isDebugEnabled()) { LOG.debug("Now processing field value segment: " + segment); } writeValue(parentNode, parentSegment, segment, targetField); } } } JsonFieldWriter();  JsonFieldWriter(ObjectMapper objectMapper); ContainerNode<?> getRootNode(); ObjectMapper getObjectMapper(); @Override void write(AtlasInternalSession session);  }### Answer:
@Test(expected = AtlasException.class) public void testWriteNullField() throws Exception { write(null); }
@Test public void testJsonFieldBooleanString() throws Exception { Path path = Paths.get("target" + File.separator + "test-write-field-byte-string.json"); String fieldPath = "/primitiveValue"; Object testObject = "abcd"; FieldType inputFieldType = FieldType.STRING; FieldType outputFieldType = FieldType.BOOLEAN; write(path, fieldPath, testObject, inputFieldType); AtlasInternalSession session = read(path, outputFieldType, fieldPath); assertEquals(false, session.head().getSourceField().getValue()); }