In this study, we employ eth-operators and spin-weighted spherical harmonics to express the ADM mass of a static spacetime in terms of the mean values of its components over a radius-$r$ sphere. While initially derived for standard spherical coordinates, we demonstrate its versatility by applying it to express a quasilocal mass, specifically the Bartnik mass, for surfaces $\mathrm{\ensuremath{\Sigma}}$ representing linear perturbations of the 2D-sphere in the 3D-Euclidean manifold. Additionally, leveraging this formulation, we propose a neural network approach for numerically constructing static metrics with an inner boundary $\mathrm{\ensuremath{\Sigma}}$, viewed as general perturbations of the 2D sphere with a specified Bartnik mass.