Select Git revision
-
Md. Alim Ul Karim authored
JsonResult -> Json, JsonResultsCollection ## Introduction JsonResult -> Json, JsonResultsCollection features added, now jsonResult can be saved into or marshal into bytes. JsonResult can be collected as JsonResultsCollection, it can also be marshalled ## Sample Code ```go items := &[]string{ "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", } // collectionPtr := corestr.NewCollectionPtrUsingStrings(items, 0) collection := corestr.NewCollectionUsingStrings(items, false) jsonResults := corejson.NewResultsCollectionUsingJsoners(1, collection) jsonResultFromResults := jsonResults.Json() fmt.Println(jsonResultFromResults.JsonString()) res2 := corejson.EmptyResultsCollection() res2.ParseInjectUsingJson(jsonResultFromResults) fmt.Println(res2.Json().JsonString()) collect2 := corestr.EmptyCollection() // res2.InjectIntoAt(0, collect2) res2.UnmarshalAt(0, collect2) fmt.Println(collect2) ``` ## Output ```notes {"GenericJsonCollection":[{"Bytes":"eyJTdHJpbmdzQ29sbGVjdGlvbiI6WyIwMCIsIjAxIiwiMDIiLCIwMyIsIjA0IiwiMDUiLCIwNiIsIjA3IiwiMDgiLCIwOSIsIjEwIiwiMTEiLCIxMiJdfQ==","Error":"","HasError":false}]} {"GenericJsonCollection":[{"Bytes":"eyJTdHJpbmdzQ29sbGVjdGlvbiI6WyIwMCIsIjAxIiwiMDIiLCIwMyIsIjA0IiwiMDUiLCIwNiIsIjA3IiwiMDgiLCIwOSIsIjEwIiwiMTEiLCIxMiJdfQ==","Error":"","HasError":false}]} - 00 - 01 - 02 - 03 - 04 - 05 - 06 - 07 - 08 - 09 - 10 - 11 - 12 Process finished with exit code 0 ``` See merge request !39
Md. Alim Ul Karim authoredJsonResult -> Json, JsonResultsCollection ## Introduction JsonResult -> Json, JsonResultsCollection features added, now jsonResult can be saved into or marshal into bytes. JsonResult can be collected as JsonResultsCollection, it can also be marshalled ## Sample Code ```go items := &[]string{ "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", } // collectionPtr := corestr.NewCollectionPtrUsingStrings(items, 0) collection := corestr.NewCollectionUsingStrings(items, false) jsonResults := corejson.NewResultsCollectionUsingJsoners(1, collection) jsonResultFromResults := jsonResults.Json() fmt.Println(jsonResultFromResults.JsonString()) res2 := corejson.EmptyResultsCollection() res2.ParseInjectUsingJson(jsonResultFromResults) fmt.Println(res2.Json().JsonString()) collect2 := corestr.EmptyCollection() // res2.InjectIntoAt(0, collect2) res2.UnmarshalAt(0, collect2) fmt.Println(collect2) ``` ## Output ```notes {"GenericJsonCollection":[{"Bytes":"eyJTdHJpbmdzQ29sbGVjdGlvbiI6WyIwMCIsIjAxIiwiMDIiLCIwMyIsIjA0IiwiMDUiLCIwNiIsIjA3IiwiMDgiLCIwOSIsIjEwIiwiMTEiLCIxMiJdfQ==","Error":"","HasError":false}]} {"GenericJsonCollection":[{"Bytes":"eyJTdHJpbmdzQ29sbGVjdGlvbiI6WyIwMCIsIjAxIiwiMDIiLCIwMyIsIjA0IiwiMDUiLCIwNiIsIjA3IiwiMDgiLCIwOSIsIjEwIiwiMTEiLCIxMiJdfQ==","Error":"","HasError":false}]} - 00 - 01 - 02 - 03 - 04 - 05 - 06 - 07 - 08 - 09 - 10 - 11 - 12 Process finished with exit code 0 ``` See merge request !39
ResultModel.go 561 B
package corejson
import "gitlab.com/evatix-go/core/constants"
type ResultModel struct {
Bytes *[]byte
Error string
HasError bool
}
func NewModel(result *Result) *ResultModel {
if result == nil {
return &ResultModel{
Bytes: &[]byte{},
Error: constants.EmptyString,
}
}
model := &ResultModel{}
return transpileResultToModel(result, model)
}
func NewFromModel(model *ResultModel) *Result {
if model == nil {
return &Result{
Bytes: nil,
Error: nil,
}
}
result := &Result{}
return transpileModelToResult(model, result)
}