title: Common method to change nullable property for all elements of any Spark sql StructType in Scala
body: <p>Is there a common method to change nullable property for all elements of any specified StructType? it might be nested StructType.</p>
  
  <p>I saw @eliasah marked it as duplicate with <a href="https://stackoverflow.com/questions/39734453/spark-dataframe-column-nullable-property-change">Spark Dataframe column nullable property change</a>. But they are different, as it cannot solve hierarchy/nested StructType, that answer is only for one level.</p>
  
  <p>for example:</p>
  
  <pre><code> root
   |-- user_id: string (nullable = false)
   |-- name: string (nullable = false)
   |-- system_process: array (nullable = false)
   |    |-- element: struct (containsNull = false)
   |    |    |-- timestamp: long (nullable = false)
   |    |    |-- process: string (nullable = false)
   |-- type: string (nullable = false)
   |-- user_process: array (nullable = false)
   |    |-- element: struct (containsNull = false)
   |    |    |-- timestamp: long (nullable = false)
   |    |    |-- process: string (nullable = false)
  </code></pre>
  
  <p>I want to change nullalbe to true to all elements, the result should be :</p>
  
  <pre><code> root
   |-- user_id: string (nullable = true)
   |-- name: string (nullable = true)
   |-- system_process: array (nullable = true)
   |    |-- element: struct (containsNull = true)
   |    |    |-- timestamp: long (nullable = true)
   |    |    |-- process: string (nullable = true)
   |-- type: string (nullable = true)
   |-- user_process: array (nullable = true)
   |    |-- element: struct (containsNull = true)
   |    |    |-- timestamp: long (nullable = true)
   |    |    |-- process: string (nullable = true)
  </code></pre>
  
  <p>Attached is a sample of JSON schema of StructType for convenience testing:</p>
  
  <pre><code>val jsonSchema="""{"type":"struct","fields":[{"name":"user_id","type":"string","nullable":false,"metadata":{}},{"name":"name","type":"string","nullable":false,"metadata":{}},{"name":"system_process","type":{"type":"array","elementType":{"type":"struct","fields":[{"name":"timestamp","type":"long","nullable":false,"metadata":{}},{"name":"process_id","type":"string","nullable":false,"metadata":{}}]},"containsNull":false},"nullable":false,"metadata":{}},{"name":"type","type":"string","nullable":false,"metadata":{}},{"name":"user_process","type":{"type":"array","elementType":{"type":"struct","fields":[{"name":"timestamp","type":"long","nullable":false,"metadata":{}},{"name":"process_id","type":"string","nullable":false,"metadata":{}}]},"containsNull":false},"nullable":false,"metadata":{}}]}"""
  DataType.fromJson(jsonSchema).asInstanceOf[StructType].printTreeString()
  </code></pre>